Search code examples
javascriptajaxinternet-explorerinternet-explorer-9xdomainrequest

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


We discovered our ajax call to a JSON resouce wasn't working in IE9, and that we had to use the X Domain Request API. But my call is simply not calling the "onload" function unless the browser is set to compatibility mode- which is not an option.

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();

Solution

  • Issue was caused by an apparent bug in IE9 which was causing XDR calls to abort. The solution was to overwrite the default xdr.onprogress method with an empty function:

    xdr.onprogress = function () { };
    

    This helpful blog post by Perry Mitchell found the problem. It's interesting that it was aborting every time except in compatability mode- maybe the timeout was being effected by the fact I was running IE9 in a virtual machine.