跨越跨域策略获取JavaScript
问题描述:
这是我的代码跨越跨域策略获取JavaScript
function load() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("change").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "https://www.example.com/xyz.txt", true);
xhttp.send();
}
为xhttp.open
的网址就是一个例子URL与一个txt文件中的另一个领域。我可以在我的代码中添加什么以使其工作?谢谢。
你不能从客户端。该来源必须允许您访问,使用JSONP或使用代理。 –