22

Fellow coders, I have asked this question before but did not get a conclusive answer to it. The question is: how much data can i safely return from and ajax post call before i run into some limitation somewhere?

The scenarios are basically like this: front-end makes an ajax call to a php controller/model. the controller returns a bunch or rows from the database or returns some html representing some report which will be stored in a js string var to be displayed later.

I see two limitations here: the size of the data returned through the ajax call and max size the js var can hold.

Anyone knows what the limits are?

thanks

djeetee
  • 1,799
  • 7
  • 24
  • 36

2 Answers2

15

See this answer: Javascript maximum size for types?

In short, unless the browser specified otherwise, variable sizes are not subject to a restriction. As for Ajax: There's no limit, unless defined server-side (such as this one).

Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • 1
    Thanks Rob. Any idea how to set the limit in environments other than .NET? – djeetee Sep 13 '11 at 14:50
  • I am not aware of any other server-defined response limitations. You only have to run one test on your server (environment) to confirm my statement. A server can be configured to reject too large request, using `.htaccess` for example: `LimitRequestBody` and [`LimitXMLRequestBody`](http://httpd.apache.org/docs/2.2/mod/core.html#limitxmlrequestbody). – Rob W Sep 13 '11 at 15:07
0

I don't think either factor you listed would be an issue. What I would look at are:

  • The amount of time the user is willing to wait for the response. Also, your server-side programming language or web server might impose a limit on the length of any one request.
  • The amount of RAM the client has. Even if there is no variable size limit, eventually the computer will run out of space.

In these situations, you are almost always better off delivering smaller chunks of the data at a time and allowing the user to load what data they need (either by granulation [showing summaries and letting them drill down], or pagination / search). No one wants to wait 10 minutes for the site to load, and HTTP doesn't really handle large requests all that well.

Zack Bloom
  • 8,309
  • 2
  • 20
  • 27