我似乎无法让XMLHttpRequest()在跨域工作。我能够通过XDomainRequest()让它跨域工作,但我需要做同步请求。
var url = 'http://phpfilethatspitsoutjson.com';
// Can't get this to work
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.send(null);
// This does work
xdr = new XDomainRequest(); // Creates a new XDR object.
xdr.open("GET", url); // Creates a cross-domain connection with our target server using GET method.
xdr.send(); //Send string data to server
xdr.onload = function () {
};
我也有标题(“Access-Control-Allow-Origin:*”);在我的网址中设置。