长轮询和 IE 的 XDomainRequest 对象
我正在尝试实现一个聊天应用程序,它使用长轮询从远程(跨域)服务器获取消息。
有没有办法用 XDomainRequest 来做到这一点?看来我的连接总是在随机的秒/毫秒(通常大约 1-3 秒)后终止,而不是等待服务器响应。
IE 开发工具告诉我请求已“中止”,没有收到任何数据。
XDomainRequest 是否不适合长轮询,或者我在这里遗漏了什么?
I'm trying to implement a chat app that uses long polling to get messages from a remote (cross domain) server.
Is there any way to do this with a XDomainRequest? It seems my connections always get terminated after a random amount of seconds/miliseconds (usually about 1-3 secs) instead of waiting for the server to respond.
The IE dev toools thell me that the request has been "aborted" with no data received.
Is the XDomainRequest just not fit for long polling or am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 jQuery iecors 库也有这个问题,作为竞争条件。尽管 Fiddler 显示 200 响应,但 IE 网络控制台将请求显示为“中止”。
经过几轮顽固的谷歌搜索后,我发现了这个链接,它建议填写所有回调处理程序。我怀疑 onProgress 只是在请求被沉重的页面减慢时被调用并且失败,导致我的竞争行为。
IE9 XDomainRequest 发出的请求可能会中止,如果未指定所有事件处理程序
对于 jquery.iecors.js,除了一些变量之外,它还缺少 onprogress 处理程序名字错别字。添加这一行似乎可以修复它。
Had this problem too, as a race condition, using the jQuery iecors library. The IE network console showed the request as "abort" despite Fiddler showing a 200 response.
After a few stubborn rounds of googling, I came across this link which recommends filling out all the callback handlers. I suspect that onProgress was only being called, and failing, when the request was slowed by a heavy page, leading to my race behavior.
IE9 XDomainRequest issued requests may abort if all event handlers not specified
For jquery.iecors.js, it was missing the onprogress handler, in addition to a few variable name typos. Adding this line seems to fix it.
对我来说,问题涉及使用 XDomainRequests 作为单个批处理函数运行的多个查询函数。 WebTools 显示对远程服务器的所有请求都会中止,但最后一个除外。在每个查询工作之前运行alert(query)。因此,我最终将 XDR 调用(例如 new window.XDomainRequest)移至循环内,以便为远程服务器的每个查询创建一个新实例。每个结果都通过 getElementById(id).value 插入到不同的输入框中。添加延迟计时器后,我可以看到它现在按顺序填充每个值,没有任何问题。没有延迟,几乎是瞬时的。
For me the issue dealt with multiple query functions running as a single batch function using XDomainRequests. WebTools showed all requests to the remote server would abort but the last. Running with alert(query) before each query worked. So I ended up moving my XDR invocation (e.g. new window.XDomainRequest) inside the loop so a new instance would be created for each query to the remote server. Each result is inserted into an different input box via getElementById(id).value. With a delay timer added I can see it runs sequentially filling in each value now with no issues. Without delay it is virtually instantaneous.