如何确保正确读取非常延迟的 AJAX 调用
我有一个文件需要处理许多其他文件,处理时间可能长达 30 分钟。我在前端对文件发出 AJAX 请求。该文件将有关完成百分比的信息输出到另一个临时文件。当它完成时,它会输出一条成功消息作为其自己的 XML 输出(而不是输出到 tmp 文件)。
我遇到的问题是,当处理时间很短时..比如说最多 3 分钟,AJAX 请求(通过 jQuery 发出)保持活动状态。但当处理时间较长(超过4分钟)时,就会出现超时。并且 AJAX 连接被切断。我如何防止它并使其保持活动状态直到浏览器关闭?
I have a File which process many other files and may take upto 30mins to process. I do an AJAX request to the file in the front end. The file outputs to another temporary file regarding the percentage of completion. And when it finishes it outputs a success message as its own XML output (not to the tmp file).
The problem i am having is, when the processing time is small .. say max upto 3mins, the AJAX request (made through jQuery) stays alive. But a time out occurs when the processing takes longer time (above 4mins). And the AJAX connection is cut. How do i prevent it and make it stay alive till the browser is closed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你将无法做到这一点。除非它是彗星服务器,否则它可以在服务器端保持连接处于活动状态,并且当数据有任何更新时,它会推送内容。
在你的情况下,我能想到的唯一方法就是这样做:
我在ajax中成功回调了上面的内容,因为我觉得你应该从服务器端响应一些内容来告诉客户端处理尚未完成。
You won't be able to do that. Unless it is a comet server, that can keep the connection alive at the server side and when there is any update to the data, it pushes out the contents.
In your case, the only way i can think of is doing this:
I have a success call back above in ajax, because i feel you should response something from your server side to tell the client that the processing is not yet done.