【发布时间】:2023-03-20 18:59:01
【问题描述】:
我正在循环发送 ajax 调用。它仅适用于前两次迭代,然后抛出异常内部服务器错误 500,描述为“JSON 请求太大而无法序列化”这里是代码:
<script>
var things = new Array();
var total = 0;
function Load() {
$.ajaxSetup({ cache: true, jsonpCallback: 'quranData' }); // define ajax setup
for (var counter = 1; counter < 4; counter++) {
(function (counter) {
setTimeout(function () {
$.getJSON("http://api.globalquran.com/surah/" + counter + "/quran-simple?jsoncallback=?", {
format: "jsonp"
}, function (Obj) {
$.each(Obj.quran, function (i, by)
{
$.each(by, function (verseNo, line)
{
var obj = new Object();
obj.surah = line.surah;
obj.ayah = line.ayah;
obj.verse = line.verse;
things.push(obj);
total++;
});
});
});
}, counter * 500);
}(counter));
}
return false;
}
服务器端:
[HttpPost]
public ActionResult DB_Rola(List<thing> things, int count)
{
return Json(new { IsSuccess = true });
}
请告诉我如何处理它?
【问题讨论】:
-
您可能希望在 web.config 中设置
maxJsonLength。 stackoverflow.com/questions/10966328/…