Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
跨域策略javascript_Javascript_Ajax - Fatal编程技术网

跨域策略javascript

跨域策略javascript,javascript,ajax,Javascript,Ajax,这是我的密码 function load() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("change").innerHTML = this.responseText; }

这是我的密码

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文件的域的示例url。我可以在我的代码中添加什么才能使其工作?谢谢。

做到这一点的最好方法是使用。

您不能从客户端使用。该源必须允许您访问、使用JSONP或使用代理。您能在这里发布一个代码示例吗?我找不到任何简单的例子。@WatchYoJet——这不是代码问题。您必须配置服务器。是一个可以帮助您使用节点服务器的库。是Apache的说明。