【发布时间】:2016-10-06 02:22:30
【问题描述】:
var http = new XMLHttpRequest();
var url = "http://example.com/";
http.crossDomain = true;
http.withCredentials = true;
http.open("GET", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send();
console.log(http.responseText);
当我尝试从代码中看到的 javascript 执行跨域请求时,它会抛出一个错误 No 'Access-Control-Allow-Origin' header is present on the requested resource。因此,Origin 'http://localhost:8000' 不允许访问。我怎么能解决这个问题,因为我不相信 JSONP 的解决方案。是否有任何其他解决方案可以解决它。而且我无法控制服务器端,因为它是第三方服务器。
【问题讨论】: