Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDomainRequest problem

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 .....
like image 948
GiaNU Avatar asked Jan 19 '11 18:01

GiaNU


2 Answers

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

like image 198
Dr.Molle Avatar answered Nov 17 '22 03:11

Dr.Molle


Your problem may be the content-type sent, because XDomainRequest only support "text/plain".

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

Cheers,

Andre Pedroso

like image 7
André Pedroso Avatar answered Nov 17 '22 04:11

André Pedroso