4

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(....)
{
    ...
    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,
Skip

SkipHarris
  • 2,334
  • 1
  • 25
  • 31

3 Answers3

3

You could add following to the web.config:

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="1000000000" />
        </webServices>
    </scripting>
</system.web.extensions>
  • isn't the limit 2GB? If it was 2MB, I couldn't send MP photos over AJAX requests with JSON :) – ilter Dec 20 '13 at 16:38
1

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

Jeremy Battle
  • 1,638
  • 13
  • 18
0

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

İpek
  • 1
  • 3