Carlos Yasuda
Carlos Yasuda

Reputation: 121

Access denied with IE's XDomainRequest open("get",url)

IE suddenly started throwing this "Access is denied" error with XDomainRequest and I can't figure out what the hell is going on. Here's what I have:

if ($.browser.msie && window.XDomainRequest) {
    // Use Microsoft XDR
    var xdr = new XDomainRequest(),
        url = 'http://someurl.com/x=1&y=2';

    xdr.open("get", url);
    xdr.onload = function () {
        doTheThing();
    };
    xdr.onprogress = function(){ };
    xdr.ontimeout = function(){ };
    xdr.onerror = function () { };
    setTimeout(function(){
        xdr.send();
    }, 0);

}

The error goes with the xdr.open("get",url), the weird thing is that this code was working fine and this solution is used everywhere I searched.

Upvotes: 1

Views: 1519

Answers (1)

securecodeninja
securecodeninja

Reputation: 2515

There are restrictions in using XDomainRequest. If your page happens to be in https and your target is http, then you will get this error.

Take note that requests must be targeted to the same scheme as the hosting page. This restriction deliberately prevents HTTPS pages from making XDomainRequests for HTTP-based resources

More details can be found here:

http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

Upvotes: 2

Related Questions