Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.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 违反了AJAX源策略_Javascript_Ajax_Node.js - Fatal编程技术网

Javascript 违反了AJAX源策略

Javascript 违反了AJAX源策略,javascript,ajax,node.js,Javascript,Ajax,Node.js,我想在本地测试ajax调用。这是可能的,还是我需要使用像xampp这样的服务器?它总是说ajax调用的源代码为null,这违反了源代码策略 本地客户端:C:/index.html httpRequest.open("GET", "http://localhost:4000" + "?data=" + value, true); httpRequest.send(); 端口4000上的节点js服务器 server = http

我想在本地测试ajax调用。这是可能的,还是我需要使用像xampp这样的服务器?它总是说ajax调用的源代码为null,这违反了源代码策略

本地客户端:C:/index.html

httpRequest.open("GET", "http://localhost:4000"
               + "?data="
               + value, true);
 httpRequest.send();
端口4000上的节点js服务器

    server = http.createServer(function(req, res) {

  res.writeHead(200, {
    'Content-Type': 'text/plain',
    'Access-Control-Allow-Origin': 'file:///C:/index.html'
  });

});

您需要一个服务器。是。@putvande:他有一个。
文件://
伪协议无法由CORS验证,因为源代码为
null
或类似。您还需要使用
http://
访问该页面。还要注意,原点不包括路径;只有协议、主机名,可能还有端口。