我遇到了CORS问题,我的代码已被执行(状态码200),但在Google Chrome开发者控制台中出现了错误。
我的代码:
function callUrl(url) {
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp !== null) {
xmlhttp.open("POST", url, true);
xmlhttp.withCredentials = true;
xmlhttp.send(JSON.stringify({
}));
} else {
console.error("Your browser does not support XMLHTTP.");
}
}
callUrl('https://www.website.com/tracking?etc...');
XMLHttpRequest无法加载https://www.website.com/tracking。当请求的凭据模式为“包括”时,响应中的“Access-Control-Allow-Origin”标头的值不能是通配符“*”。因此,源'http://localhost:8888'不被允许访问。XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制。 服务器配置:
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,