我们有两个前端URL,它们需要从相同的API获取数据。
MDN文档说允许多个来源:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
但是当我得到以下结果时(在Chrome 68中):
无法加载http://localhost:8080/api/1.0/test/:'Access-Control-Allow-Origin'标头包含多个值'http://localhost:8080,http://localhost:4000',但仅允许一个。因此,不允许访问来源“ http://localhost:4000”。让服务器发送带有有效值的标头,或者,如果不透明的响应满足您的需要,请将请求的模式设置为“ no-cors”,以在禁用CORS的情况下获取资源。
let a = prompt ("Input value of 'a'");
let b = prompt ("Input value of 'b'");
console.log("Before Number");
console.log("a: "+a+" b: "+b+ " a + b: "+(a + b));
a = Number(a);
b = Number(b);
let result = '';
if ( a + b < 4){
result = 'Below';
} else {
result = 'Over';
}
console.log("After Number");
console.log("a: "+a+" b: "+b+ " a + b: "+(a + b));
console.log(result);
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: nb-NO,nb;q=0.9,no;q=0.8,nn;q=0.7,en-US;q=0.6,en;q=0.5,da;q=0.4,sv;q=0.3
Cache-Control: no-cache
Connection: keep-alive
Cookie: (...)
Host: localhost:8080
Origin: http://localhost:4000
Pragma: no-cache
Referer: http://localhost:4000/test