我有这个代码:
$.getJSON("https://restcountries.eu/rest/v2/name/" + $("#nameOfCountry").val(),
{ fullText: "true" }, function (data) {
console.log(data[0]);
$('#answer').html(data[0].capital);
});
我收到了来自其他服务器的响应。 所以我的问题是:为什么浏览器不在这里强制执行跨源策略?
最佳答案
Same Origin Policy服务器永远不会强制执行。它是由浏览器强制执行的。
在本例中,服务器已使用 the CORS standard包含 Access-Control-Allow-Origin
header ,告诉浏览器它有权与任何其他网站共享数据。
关于javascript - 为什么不执行跨源政策?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43044471/