The XDomainRequest object is a safe, reliable, and lightweight data service that allows script on any page to anonymously connect to any server and exchange data. Developers can use the XDomainRequest object when cross-site security is not an issue.
Security Alert
Cross-domain requests ("XDRs") are anonymous to protect user data. This means that servers cannot easily determine who is requesting data. To protect user privacy, respond with cross-domain data that is neither sensitive nor personally identifiable. To help prevent intranet data from being leaked to malicious Internet sites, we discourage intranet sites from making XDR data available.
Cross-domain requests require mutual consent between the Web page and the server. You can initiate a cross-domain request by creating an XDomainRequest (XDR) object with the window object, and opening a connection to a domain.
The browser will request data from the domain's server by sending an Origin header with the value of the origin. It will only complete the connection if the server responds with an Access-Control-Allow-Origin header of either * or the exact URL of the requesting page. This behavior is part of the World Wide Web Consortium (W3C)'s Web Application Working Group's draft framework on client-side cross-domain communication that the XDomainRequest object integrates with.
For example, a server's Active Server Pages (ASP) page might include the following response header:
<% Response.AddHeader("Access-Control-Allow-Origin","*") %>
Cross domain requests can only be sent and received from a Web page to URLs in the following Internet Explorer zones:
| From web page \ To URL | Intranet | Trusted(Intranet) | Trusted(Internet) | Internet | Restricted |
| Intranet | Allow | Allow | Allow | Allow | Deny |
| Trusted(Intranet) | Allow | Allow | Allow | Allow | Deny |
| Trusted(Internet) | Deny | Deny | Allow | Allow | Deny |
| Internet | Deny | Deny | Allow | Allow | Deny |
| Restricted | Deny | Deny | Deny | Deny | Deny |
The XDR protocol only works with the http:// and https:// protocols.
To use the XDR protocol, you first create an XDomainRequest object.
Then you use the open method to establish a connection with a server.
Once a connection is opened, the send method transmits data strings to the server for processing. For example:
// 1. Create XDR object
var xdr = new XDomainRequest();
// 2. Open connection with server using GET method
xdr.open("get", "http://www.contoso.com/xdr.aspx");
// 3. Send string data to server
xdr.send();