简体   繁体   English

IE9中对Handlebars资源的Require.js请求被随机中止

[英]Require.js requests for Handlebars resources are randomly aborted in IE9

We are developing a web application that uses Require.js and Handlebars, and it works correctly in all browsers except (of course) IE9. 我们正在开发一个使用Require.js和Handlebars的Web应用程序,它可以在除(当然)IE9之外的所有浏览器中正常工作。 In IE9, the requests that are made by the Handlebars Require.js module ( hbs.js ) to load Handlebars resources are randomly aborted - sometimes, they succeed, and when they fail, there is no clear pattern as to which requests fail (other than the fact that only Handlebars requests fail; all requests for JavaScript resources succeed). 在IE9中,由Handlebars Require.js模块( hbs.js )发出的用于加载Handlebars资源的请求被随机中止-有时,它们成功,并且当它们失败时,没有明确的模式确定哪些请求失败(其他而不是只有Handlebars请求失败;对JavaScript资源的所有请求都成功的事实)。 In the Network pane, the request is listed as (Aborted) , and the initiator is (Pending...) , with no further information. 在“网络”窗格中,请求被列为(Aborted) ,发起者是(Pending...) ,没有更多信息。

This is probably not a configuration error, since it works everywhere else, but rather a problem with the frameworks' browser compatibility, so I'm omitting the configuration. 这可能不是配置错误,因为它可以在其他地方使用,而是框架的浏览器兼容性问题,因此我省略了配置。 Does anyone have any idea about what is going on? 有谁知道发生了什么吗?

(Note: I have already found the solution after several hours of digging, and will post it myself for the benefit of others who might encounter the same problem. The solution is already described here and here ; however, finding those answers requires that you have already figured out that XDomainRequest might be the problem, which requires digging into the framework code.) (注意:经过数小时的挖掘,我已经找到了解决方案,并将其发布给自己,以帮助可能遇到相同问题的其他人。解决方案已在此处此处进行了描述;但是,找到这些答案需要您拥有已经发现XDomainRequest可能是问题所在,这需要深入研究框架代码。)

hbs.js uses XDomainRequest in old IE versions. hbs.js在旧的IE版本中使用XDomainRequest It turns out that, in IE9, when an XDomainRequest request doesn't finish immediately, IE9 will attempt to fire the onprogress callback, and it will abort the request if the callback isn't there. 事实证明,在IE9中,当XDomainRequest请求没有立即完成时,IE9将尝试触发onprogress回调,并且如果不存在该回调,它将中止该请求。 In other words, if you do not subscribe to the XDomainRequest.onprogress callback, your requests will fail randomly in IE9 . 换句话说, 如果您不订阅XDomainRequest.onprogress回调,则您的请求将在IE9中随机失败 The hbs.js version we were using did not subscribe to this event (it has been fixed in recent versions), and adding the subscription fixed the problem: 我们使用的hbs.js版本没有订阅此事件(在最新版本中已修复),添加订阅解决了该问题:

xhr.onprogress = function() {};

immediately after 之后立马

if (useXdr) {
    xhr.onload = function () { callback(xhr.responseText); }

in hbs.js . hbs.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM