Javascript XMLHttpRequest在32位机器上不工作,IE10处于IE8标准文档模式
想知道以前是否有人碰到过这个奇怪的IE/javascript错误 在IE8标准文档模式下使用IE10的32位计算机上,javascript在尝试创建新的XMLHttpRequest对象时返回TypeError。这是一个问题,因为我们的一个页面通过与X-UA兼容的IE=8元标记强制执行IE8标准(这是页面的要求) 新建window.XMLHttpRequest()Javascript XMLHttpRequest在32位机器上不工作,IE10处于IE8标准文档模式,javascript,internet-explorer,xmlhttprequest,32bit-64bit,x-ua-compatible,Javascript,Internet Explorer,Xmlhttprequest,32bit 64bit,X Ua Compatible,想知道以前是否有人碰到过这个奇怪的IE/javascript错误 在IE8标准文档模式下使用IE10的32位计算机上,javascript在尝试创建新的XMLHttpRequest对象时返回TypeError。这是一个问题,因为我们的一个页面通过与X-UA兼容的IE=8元标记强制执行IE8标准(这是页面的要求) 新建window.XMLHttpRequest() TypeError:对象不支持此操作 来自64位机器(IE8标准中的IE10)的完全相同的代码行可以正常工作。 32位IE10 I
TypeError:对象不支持此操作 来自64位机器(IE8标准中的IE10)的完全相同的代码行可以正常工作。
32位IE10 IE8标准
64位IE10 IE8标准
我在使用angularjs 1.2.9版时遇到了类似的问题。事实证明,angular在检测window.XMLHttpRequest()的可用性方面做得并不好。jQuery的方法更彻底一些 angularjs 1.2.9
function createXhr(method) {
// IE8 doesn't support PATCH method, but the ActiveX object does
/* global ActiveXObject */
return (msie <= 8 && lowercase(method) === 'patch')
? new ActiveXObject('Microsoft.XMLHTTP')
: new window.XMLHttpRequest();
}
对我来说,修复方法是在angular的createXhr方法中添加一个检查IE8文档模式的附加条件:
function createXhr(method) {
// IE8 doesn't support PATCH method, but the ActiveX object does
/* global ActiveXObject */
return ((msie <= 8 && lowercase(method) === 'patch') ||
(msie >= 8 && document.documentMode == 8))
? new ActiveXObject('Microsoft.XMLHTTP')
: new window.XMLHttpRequest();
}
函数createXhr(方法){
//IE8不支持补丁方法,但ActiveX对象支持
/*全局ActiveXObject*/
返回((msie=8&&document.documentMode==8))
?新的ActiveXObject('Microsoft.XMLHTTP')
:new window.XMLHttpRequest();
}
另一种方法是实现jQuery的方法,该方法查看ActiveXObject是否可用。如果是,则尝试创建标准XMLHttpRequest,如果失败,则返回ActiveX替代方案
function createXhr(method) {
// IE8 doesn't support PATCH method, but the ActiveX object does
/* global ActiveXObject */
return ((msie <= 8 && lowercase(method) === 'patch') ||
(msie >= 8 && document.documentMode == 8))
? new ActiveXObject('Microsoft.XMLHTTP')
: new window.XMLHttpRequest();
}