我将JSON数据发布到ASP.NET MVC2服务器。我发布大型JSON字符串(其中包含base64编码的文件流,从本地文件系统读取)。 jQuery ajax调用可以正常工作,最大文件大小约为2.5Mb。一旦超过这个大小,ajax调用失败(永远不会到达控制器)。我无法准确检测到错误是什么 - 它似乎没有填充错误变量。jQuery .ajax发布失败,带有大型JSON对象
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));
}
});
其中_moleculefilestream是大base64编码流。
我的web.config包括以下内容:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
任何人有什么高见?
这样做的伎俩 - 谢谢! – Journeyman