Javascript 违反了AJAX源策略
我想在本地测试ajax调用。这是可能的,还是我需要使用像xampp这样的服务器?它总是说ajax调用的源代码为null,这违反了源代码策略 本地客户端:C:/index.htmlJavascript 违反了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
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://
访问该页面。还要注意,原点不包括路径;只有协议、主机名,可能还有端口。