【发布时间】:2018-05-01 11:22:45
【问题描述】:
我遇到了 CORS 问题,问题是我的代码已执行(status 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,
【问题讨论】:
标签: javascript xmlhttprequest cors serverless serverless-framework-offline