如何防止 FireFox “旋转”带有长轮询请求?
我正在使用以下内容进行长轮询请求...
$.getJSON(url, function(data) {
...
});
直到 30 秒过去或有信息要发送(长轮询)后,请求才会完成。
问题是 Firefox 是唯一会在底部显示“等待 URL...”的浏览器。有什么办法可以防止这种情况发生吗?
I'm using the following for a long-polling request...
$.getJSON(url, function(data) {
...
});
The request won't finish until either 30 seconds have passed or there is information to send (long-polling).
The problem is that Firefox is the only browser that will display "Waiting for URL..." at the bottom. Is there any way to prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这非常糟糕,因为有些用户只是坐在那里等待页面“加载”,而 Firefox 并不是唯一这样做的浏览器。不幸的是,我认为不使用一些相当奇特的技术就没有简单的方法来解决这个问题。
如果持续时间是由于服务器处理时间而不是到客户端的数据传输,您可以尝试的一件事是使用伪异步调用。当您收到请求时,在服务器上启动一个新线程并返回一个令牌,这将清除该消息。每“x”秒将令牌发送回服务器以检查请求是否完成。只需确保当前请求所需的任何安全/身份验证方法都复制到异步请求的两端即可。
This is pretty bad because some users will just sit there and wait for the page to 'load', and Firefox is not the only browser that does this. Unfortunately, I don't think there is an easy way to fix this without using some fairly exotic techniques.
One thing you might try provided the duration is due to server processing time, not data transfer to the client, is using an psuedo-async call. When you get the request, kick off a new thread on the server and return a token, that will clear the message. Every 'x' seconds send the token back to the server to check to see if the request is completed. Just make sure whatever security/authentication methods you need for the current request are replicated on both ends of the async request.