Internet Explorer 9- X Domain Request仅在兼容模式下工作

Internet Explorer 9- X Domain Request only works in compatability mode

本文关键字:模式 工作 Explorer Domain Request Internet      更新时间:2023-09-26

我们发现对JSON资源的ajax调用在IE9中不起作用,我们不得不使用X Domain Request API。但是我的调用只是不调用"onload"函数,除非浏览器设置为兼容模式-这不是一个选项。

var xdr = new XDomainRequest(); // Use Microsoft XDR
xdr.open('get', uri);
xdr.onload = function () {
    //debugger;
    var JSON = $.parseJSON(xdr.responseText);
    if (JSON == null || typeof (JSON) == 'undefined') {
        JSON = $.parseJSON(data.firstChild.textContent);
    }
    ieCallback(JSON);
 };
xdr.onerror = function () {
    _result = false;
};
xdr.send();

问题是由IE9中一个明显的错误引起的,该错误导致XDR调用中止。解决方案是覆盖默认的xdr。使用空函数的Onprogress方法:

xdr.onprogress = function () { };
Perry Mitchell的这篇有用的博客文章发现了这个问题。有趣的是,除了在兼容模式下,它每次都会中止-可能超时是由于我在虚拟机中运行IE9而受到影响。