Jou*_*man 5 ajax jquery post json
我将JSON数据发布到ASP.NET MVC2服务器.我发布了大型JSON字符串(其中包含一个base64编码的文件流,从本地文件系统读取).jQuery ajax调用工作正常,文件大小约为2.5Mb.一旦超过这个大小,ajax调用就会失败(永远不会到达控制器).我无法准确地检测到错误是什么 - 它似乎没有填充错误变量.
ajax调用如下:
$.ajax({
type: "POST",
dataType: 'json',
timeout: 10000,
url: "/Molecule/SaveMolecule",
data: { jsonpost: postdata, moleculetype: _moleculeType, moleculefilestream: _moleculefilestream, changedproducts: stringifiedChangedProducts }, // NOTE the moleculeType being added here
success: function (data) {
if (data.rc == "success") {
$.log('ServerSuccess:' + data.message);
molecule_updateLocalInstance();
_bMoleculeIsDirty = false;
if (bReturnToMoleculeList != null && bReturnToMoleculeList == true) {
navigator_Go('/Molecule/Index/' + _moleculeType);
}
else {
_saveMoleculeButtonFader = setTimeout(function () {
$('#profilesave-container').delay(500).html('<img src="/content/images/tick.png" width="32px" height="32px" /><label>' + _moleculeSingularTerm + ' was saved</label>').fadeIn(500);
_saveMoleculeButtonFader = setTimeout(function () { $('#profilesave-container').fadeOut(1000); }, 2000);
}, 500);
}
} else {
$.log('ServerUnhappy:' + data.message);
RemoveMoleculeExitDialog();
}
}
, error: function (jqXHR, textStatus, errorThrown) {
alert('Save failed, check console for error message:' +textStatus+' '+ errorThrown);
MarkMoleculeAsDirty();
$.log('Molecule Save Error:' + helper_objectToString(textStatus+' '+errorThrown));
}
});
Run Code Online (Sandbox Code Playgroud)
其中_moleculefilestream是大型base64编码流.
我的web.config包括以下内容:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Run Code Online (Sandbox Code Playgroud)
有人有什么好主意吗?
尝试设置 httpRuntime 的 maxRequestLength 属性。
http://msdn.microsoft.com/en-us/library/e1f13641.aspx
您可以通过位置标签将其设置为您需要的控制器/操作。