繁体   English   中英

由于大型JSON,Ajax导致500 Internal Server Error

[英]Ajax results in 500 Internal Server Error because of large JSON

我有以下代码

阿贾克斯电话

$.ajax({
type: "POST",
dataType: "json",
async: false,
contentType: "application/json; charset=utf-8",
url: "Account/SomeFunc",
data: JSON.stringify(dataToSend),

success: function (res) {
//some code

},

error: function (res, textStatus, errorThrown) {
//some code

}
});

在服务器端

public ActionResult SomeFunc()
    {
        //some code
        VeryBigObject result = getResult();

        if (result == null)
            return null;

        var jsonResult = Json(result, JsonRequestBehavior.AllowGet);
        jsonResult.MaxJsonLength = int.MaxValue;

        return jsonResult;
    }

结果变量可以很小,但有时它是一个很大的对象。 当对象足够小时,代码可以工作并且激活了ajax成功代码,但是当结果足够大时,代码将失败,并显示500 Internal Server Error。 我不能将MaxJsonLength设置得更大一些,因为它是int,但是有时我需要发送一些大数据。我该怎么办?

使用以下web.config的代码。 它将解决您的问题。

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="900000" />
      </webServices>
    </scripting>
 </system.web.extensions>

当我遇到大型json数据的类似问题时,Web配置中maxJsonLength的增加对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM