【发布时间】:2015-12-03 17:33:39
【问题描述】:
我在 AJAX 请求中遇到了一个错误,该错误仅发生在大型 JSON 对象中。
我正在使用画布上的 JSON 对象(矩形、线条、freedraw 等)。当用户完成并想要保存它以供以后使用时,他们会保存它并进行其他业务。当绘图非常大以至于 POST 不会命中控制器方法时,我遇到了问题。
我在 web.config 中添加了多个配置设置,包括:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="86753090" />
</webServices>
</scripting>
</system.web.extensions>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<httpRuntime maxRequestLength="1048576"/>
所有这些都没有解决问题;请求代码如下。
$('#submitSketch').click(function () {
var jsonString = JSON.stringify(lc.getSnapshot());
$.ajax({
type: "POST",
url: "@Url.Action("SaveSketch")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ id: $("#currLevelId").val(), jsonString: jsonString })
})
.done(function (data) {
alert("Saved");
})
.fail(function (XMLHttpRequest, textStatus, error) {
alert("Unable to save!");
});
});
方法的Header是:
[HttpPost]
public ActionResult SaveSketch(int id, string jsonString)
任何帮助将不胜感激。 只要500
发布http://localhost:59394/Job/SaveSketch
500(内部服务器错误)发送@ jquery-1.9.1.js:8526
jQuery.extend.ajax @ jquery-1.9.1.js:7978
(匿名函数)@ 70:147
jQuery.event.dispatch @ jquery-1.9.1.js:3074
elemData.handle@jquery-1.9.1.js:2750
【问题讨论】:
-
您的浏览器控制台有错误吗?
-
问题现在出现错误
-
您应该能够通过检查浏览器的 Ajax 请求来获得更好的信息。您应该准确地看到服务器返回给您的内容。
-
使用 Visual Studio 断点! 500 错误意味着您的代码正在崩溃
-
方法第一行有个断点;它在它面前破裂了。
标签: c# json ajax asp.net-mvc