XDomainRequest problem

GiaNU picture GiaNU · Jan 19, 2011 · Viewed 23.5k times · Source

I'm trying to make a asynchronous call to a service that returns json using XDomainRequest (IE8). The problem is that i always get an error (the onerror event is fired, and the responseText is always null), i'm using fiddler to check the response of the service and i seems right (I can see the json object returnig), this only happen in IE8 when using XDomainRequest, the same functionality implemented in JQuery works fine.

Any clue would be appreciated. Thanks!

P.S.: This is my javascript code:

.....
  if (jQuery.browser.msie && window.XDomainRequest) {
    //Use Microsoft XDR
    var xdr = new XDomainRequest();
    xdr.open("post", url);
    xdr.onload = function () {
       alert("Loading");
       alert(xdr.responseText);
    };
    xdr.onsuccess = function() {
       alert("Success!");
       alert(xdr.responseText);
    };
    xdr.onerror = function() {
       alert("Error!");
       alert(xdr.responseText);
    };
    xdr.onprogress = function() {
       alert("Progress");
       alert(xdr.responseText);
    };
    xdr.timeout = 1000;
    xdr.send("data: " + escape(data));
    var response = xdr.responseText;
 } else .....

Answer

Dr.Molle picture Dr.Molle · Jan 19, 2011

Are you sure that the service is sending a Access-Control-Allow-Origin-header matching the requesting URL?