How to increase 2MB limit on AJAX JSON response w/ ASP.NET MVC
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.
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
});
In my controller, I am using the Json() action result method:
public ActionResult GetItems(....)
{
.开发者_如何学Go..
return Json(packet);
}
When I watch the call in Fiddler it comes back with a HTTP 500 response.
I tried setting the maxJsonLength in the Web.config file as shown here, but that doesn't seem to make any difference.
Any suggestions on how to allow a response over 2MB?
Thanks in advance,
SkipYou could add following to the web.config:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="1000000000" />
</webServices>
</scripting>
</system.web.extensions>
I am not sure if you are running your own server or if you are on a hosted solution, however, we recently ran into this but with a 30MB limit. Anything greater would not fire success methods. So if you are on a shared host this setting might have been set to 2MB for you.
We fixed this by changing the maxAllowedContentLength as described here: http://www.webtrenches.com/post.cfm/iis7-file-upload-size-limits
Changing executionTimeout and maxRequestLength might be the solution cause you stated: "my 'success' method never gets called." (It solved my problem with adding this.)
<configuration>
<system.web>
<httpRuntime maxRequestLength="500000000" executionTimeout="120" />
</system.web>
<configuration>
Source : https://webconnection.west-wind.com/docs/_4lp0zgm9d.htm
精彩评论