XDomainRequest object for cross-sites Ajax

The XDomainRequest object is not standard. It has been created by Microsoft and implemented in Internet Explorer 8 and 9 for exchanging data between domains, just as the XMLHttpRequest object exchanges data between the browser and the server on a single domain.

Here is the current specification of the XDomainRequest object.

Attributes

contentType

responseText

timeout

Events

onerror

onload

onprogress

ontimeout

Methods of XDomainRequest

open

send

abort

Examples

Complete code for a GET request with XDomainRequest.

xdr = new XDomainRequest(); 

xdr.onload=function()
{
    alert(xdr.responseText);
}
xdr.open("GET", "http://www.example.com/myfile.txt");
xdr.send(); 

Complete code for a POST request.

xdr = new XDomainRequest(); 

xdr.onload=function()
{
    alert("completed");
}
xdr.open("POST", "http://www.example.com/script.php");
xdr.send("some data to send"); 

Conclusion

There is no major difference between the interfaces of XDomainRequest and that of its predecessor, the XMLHttpRequest object (originally created by Microsoft as well). It should be noted, however, two useful additions: ontimeout and onprogress.

Another difference too, the onload event which replaces onreadystatechange and readyState and in fact simplifies the use of the object.
However onload and onprogress are planned for the Level 2 of the specification of XHR.

You should not use this object for a public usage at this time. On the one hand, the definition is not complete, on the other hand, it only works on Internet Explorer 8 and 9 and is replaced by XHR 2 on IE 10. You can use a substitute as described in the article Cross-site Ajax.

More information


© 2008-2013 Xul.fr