Tôi đang đăng dữ liệu JSON lên máy chủ ASP.NET MVC2. Tôi đăng các chuỗi JSON lớn (kết hợp với luồng tệp được mã hóa base64, đọc từ hệ thống tệp cục bộ). Cuộc gọi jQuery ajax hoạt động tốt với kích thước tệp khoảng 2.5Mb. Khi đã ở trên kích thước này, cuộc gọi ajax sẽ không thành công (không bao giờ đến bộ điều khiển). Tôi không thể phát hiện chính xác lỗi là gì - nó dường như không cư trú trong các biến lỗi.Bài đăng jQuery .ajax không thành công với đối tượng JSON lớn
Cuộc gọi ajax là như sau:
$.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));
}
});
nơi _moleculefilestream là dòng base64 mã hóa lớn.
web.config của tôi bao gồm những điều sau đây:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Bất cứ ai có bất kỳ ý tưởng sáng?
Điều đó đã thực hiện mẹo - cảm ơn! – Journeyman