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 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.
Another alternative is adding this to your php script:
header('Access-Control-Allow-Origin: null');
header('Access-Control-Allow-Credentials: true');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.