The HTML5 new standard adds the "Cross-origin Resource sharing" feature, which enables cross-domain communication to be resolved only by configuring the HTTP protocol header.
Cross-origin Resource Sharing detailed explanation see:
Http://dvcs.w3.org/hg/cors/raw-file/tip/Overview.html
One of the most important cross-origin Resource sharing implementations is the configuration of the parameter "Access-control-allow-origin", which checks whether the cross-domain request can be passed through the secondary parameter.
such as: access-control-allow-origin:http://a.com to allow the domain name under a.com cross-domain access;
access-control-allow-origin:* means that all domain names are allowed cross-domain access.
If you need to read the read cookie:
Configuration parameters Required: Access-control-allow-credentials:true
Also set the parameter withcredentials to True when XHR initiates the request:
var xhr = new XMLHttpRequest ();
Xhr.open ();
Xhr.withcredentials = true; This is done behind Xhr.open, otherwise some versions of the browser will be abnormal, resulting in invalid settings.
Js:
VARXHR =newxmlhttprequest (); Xhr.open (' GET ', ' http://b.com/cros/ajax.php ', true); Xhr.withcredentials =true;xhr.onload =function () {alert (XHR . response);//reposhtml;}; Xhr.onerror =function () {alert (' Error making the request ');}; Xhr.send ();
HTML5 Ajax cross-domain requests