如何在AJAX JSON响应瓦特/ ASP.NET MVC增加2MB限制如何在、JSON、AJAX、ASP

2023-09-10 19:23:12 作者:白浅.

我有做一个AJAX调用时响应结束2MB的问题。任何与2MB下响应工作正常。当响应超过2MB,我的成功的方法永远不会被调用。

I am having problems making an AJAX call when the response is over 2MB. Anything with a response under 2MB works fine. When the response is over 2MB, my "success" method never gets called.

我的应用程序是ASP.NET MVC2。我正在使用jQuery AJAX调用呼叫:

My application is ASP.NET MVC2. I am making the call using the jQuery AJAX call:

$.ajax({
    type: "post",
    data: ajaxData,
    url: ajaxUrl,
    success: updateItems,
    cache: false
});

在我的控制,我使用的JSON()操作结果的方法:

In my controller, I am using the Json() action result method:

public ActionResult GetItems(....)
{
    ...
    return Json(packet);
}

当我看到提琴手调用它回来了HTTP 500响应。

When I watch the call in Fiddler it comes back with a HTTP 500 response.

我尝试设置maxJsonLength在Web.config文件,如此处,但似乎没有任何区别。

I tried setting the maxJsonLength in the Web.config file as shown here, but that doesn't seem to make any difference.

如何允许通过2MB回应任何建议?

Any suggestions on how to allow a response over 2MB?

在前进,谢谢 跳过

Thanks in advance, Skip

推荐答案

您可以添加以下到web.config中:

You could add following to the web.config:

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