jQuery 或 JavaScript ajax get 方法的返回值的大小限制?
当我使用ajax GET方法时,返回值有大小限制吗?
如果是这样,这个限制是由于 JavaScript/jQuery 造成的吗?到浏览器?到服务器?
我看过较旧的文章(5 年以上)似乎表明存在大小限制,但我找不到有关此主题的任何最新信息。
When I use an ajax GET method, is there a size limit for the return value?
If so, is this limit due to JavaScript/jQuery? To the browser? to the server?
I have seen older articles (5+ years old) that seem to indicate that there was a size limit, but I couldn't find any recent information on this topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有一个限制。它取决于体系结构和可用内存。在具有 2G 和 64 位版本的 x86_64 计算机上,它将失败并显示 InternalError: script stack spacequota is exeded,但在具有 4G 和 64 位版本的 x86_64 计算机上它将通过。
因此,它最终取决于运行和托管脚本的计算机来有效地服务请求。
如果您收到 InternalError Script Stack 消息,则仅意味着您需要升级硬件才能运行请求。
“控制”这一点的方法是进行所谓的“节流”。请参阅另一个堆栈以供参考:
如何对ajax请求进行速率限制?
Yes there is a limit. Its dependent upon architecture and available memory. On a x86_64 machine with 2G and a 64bit build, it will fail with InternalError: script stack space quota is exhausted however on a x86_64 with 4G and a 64bit build it will pass.
So it ultimately depends on the machine that is running and hosting the script to efficiently serve the request.
If you receive an InternalError Script Stack message it just means you need upgraded hardware to run the request(s).
Ways to "control" this are to do whats called "throttling". See another stack for reference on this:
How to rate-limit ajax requests?
HTTP 协议不限制任何响应的大小,jQuery 本身也不限制。因此从理论上讲,您可以将 GET 响应设置为您想要的大小。
但实际上,存在一些限制:Web 服务器可能有最大响应大小(尤其是当您缓存整个响应时)、服务器代码可能需要需要额外存储的中间处理步骤、客户端需要在处理响应数据之前将其存储在某处,浏览器上的 javascript 实现可能有额外的内存限制(您不希望流氓脚本耗尽您所有的物理 RAM:这将是一个严重的安全问题)。不过,究竟多少才算是太多,很难确定:几兆字节可能还可以,一太字节肯定不行。
请注意,请求方法在这种情况下非常无趣;上述问题对于 POST 请求或任何其他 HTTP 动词的响应同样有效。
The HTTP protocol does not limit the size of any response, and neither does jQuery itself. So theoretically speaking, you can make your GET response as big as you want.
In practice, however, there are some constraints: the web server may have a maximum response size (especially when you're caching entire responses), server code may need intermediate processing steps that require additional storage, the client needs to store the response data somewhere before processing it, the javascript implementation on the browser may have extra memory constraints (you don't want a rogue script eating up all your physical RAM: that would be a severe security problem). How much exactly is too much is pretty hard to pinpoint though: a few megabytes are probably OK, a terabyte certainly isn't.
Note that the request method is pretty uninteresting in this context; the above issues are just as valid for responses to POST requests, or any other HTTP verb.