[英]$.post() error Origin null is not allowed by Access-Control-Allow-Origin
This code: 这段代码:
$(function(){
$.get("test.html", function(data){
$(".msgs").text(data)
})
})
Gives me this console error: 给我这个控制台错误:
XMLHttpRequest cannot load file:///C:/wamp/www/JQuery%20lab/check.php?username=&password=.
Origin null is not allowed by Access-Control-Allow-Origin
What can I do to fix this error? 我该如何解决该错误?
You are viewing your HTML file directly from the webserver serving directory, not from http://localhost/
, so the browser is blocking the GET
request. 您正在直接从Web服务器服务目录而不是
http://localhost/
查看HTML文件,因此浏览器阻止了GET
请求。
Web browsers block certain kinds of JavaScript requests due to security policies, and sending a request from a local file seems to be one of them. Web浏览器由于安全策略而阻止了某些类型的JavaScript请求,从本地文件发送请求似乎就是其中之一。
Another alternative is adding this to your php script: 另一个选择是将此添加到您的php脚本中:
header('Access-Control-Allow-Origin: null');
header('Access-Control-Allow-Credentials: true');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.