Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDomainRequest in IE is giving Access is Denied error

This is the code I am using is as follows down below:

I am using IE9 and am unable to see the request being sent in the Network tab. I do have Access-Control headers set in the JSP as:

<% response.setHeader("Access-Control-Allow-Origin", "*");%>

Code to get the AJAX HTML Content from the JSP:

if ($.browser.msie && window.XDomainRequest) {

    var xdr = new window.XDomainRequest();
    xdr.open("GET", "http://dev01.org:11110/crs/qw/qw.jsp?&_=" + Math.random());
    xdr.contentType = "text/plain";
    xdr.timeout = 5000;
    xdr.onerror = function () {
        console.log('we have an error!');
    }
    xdr.onprogress = function () {
        console.log('this sucks!');
    };
    xdr.ontimeout = function () {
        console.log('it timed out!');
    };
    xdr.onopen = function () {
        console.log('we open the xdomainrequest');
    };
    xdr.onload = function() {
        alert(xdr.responseText);
    };
    xdr.send(null);
} else { ...... }

I am getting a Access is Denied Error. Any help would be much appreciated!

like image 592
akoy Avatar asked Nov 20 '12 17:11

akoy


1 Answers

Requests must be targeted to the same scheme as the hosting page

In your example you are doing request to:

http://dev01 ...

And you should do this from HTTP protocol.

For example: If your site, where js script is located: http://dev.org You can do this:

xhr = new XDomainRequest();
xhr.open("GET", "http://dev01.org?p=1");

but this throws "Access denied":

xhr = new XDomainRequest();
xhr.open("GET", "https://dev01.org?p=1");
like image 143
Victor Perov Avatar answered Dec 30 '22 17:12

Victor Perov