Javascript ajax返回数据的最大大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7392694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 02:06:28  来源:igfitidea点击:

Maximum size of ajax returned data

javascriptajax

提问by djeetee

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?

各位程序员,我以前问过这个问题,但没有得到最终的答案。问题是:在遇到某些限制之前,我可以安全地从 ajax post 调用返回多少数据?

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.

场景基本上是这样的:前端对 php 控制器/模型进行 ajax 调用。控制器从数据库返回一堆或几行,或者返回一些表示某些报告的 html,这些报告将存储在 js 字符串 var 中以供稍后显示。

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

我在这里看到两个限制:通过 ajax 调用返回的数据大小和 js var 可以容纳的最大大小。

Anyone knows what the limits are?

有谁知道限制是什么?

thanks

谢谢

采纳答案by Rob W

See this answer: Javascript maximum size for types?

请参阅此答案:类型的 Javascript 最大大小?

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).

简而言之,除非浏览器另有说明,否则可变大小不受限制。至于 Ajax:没有限制,除非定义了服务器端(比如这个)。

回答by Zack Bloom

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.
  • 用户愿意等待响应的时间量。此外,您的服务器端编程语言或 Web 服务器可能会对任何一个请求的长度施加限制。
  • 客户端拥有的 RAM 量。即使没有可变大小限制,最终计算机也会耗尽空间。

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.

在这些情况下,您几乎总是最好一次提供较小的数据块,并允许用户加载他们需要的数据(通过粒度[显示摘要并让它们向下钻取],或分页/搜索)。没有人愿意为网站加载等待 10 分钟,而且 HTTP 并不能很好地处理大型请求。