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 .....
Are you sure that the service is sending a Access-Control-Allow-Origin-header matching the requesting URL?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With