简体   繁体   English

$ .post()错误Access-Control-Allow-Origin不允许使用原点null

[英]$.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.

相关问题 Access-Control-Allow-Origin不允许使用Chrome Origin null - Chrome Origin null is not allowed by Access-Control-Allow-Origin 无法与jsonp配合使用的Access-Control-Allow-Origin不允许使用Origin null - Origin null is not allowed by Access-Control-Allow-Origin not working with jsonp Access-Control-Allow-Origin不允许使用原点null - Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许来源 - Origin is not allowed by Access-Control-Allow-Origin 交叉请求时出错:“ Access-Control-Allow-Origin不允许原产”? - Error on cross request: “Origin is not allowed by Access-Control-Allow-Origin”? 使用JQuery更新OData时出现错误“ Access-Control-Allow-Origin不允许Origin null” - Error “Origin null is not allowed by Access-Control-Allow-Origin” when using JQuery to update OData jQuery使用WCF。 错误:XMLHttpRequest无法加载Access-Control-Allow-Origin不允许使用Origin null - Jquery to consume WCF. error: XMLHttpRequest cannot load Origin null is not allowed by Access-Control-Allow-Origin 对于从 file:// URL 运行的应用程序发出的请求,“Access-Control-Allow-Origin 不允许使用 Origin null”错误 - “Origin null is not allowed by Access-Control-Allow-Origin” error for request made by application running from a file:// URL Twitter:仅限应用程序的身份验证错误Access-Control-Allow-Origin不允许使用Origin null - Twitter :Application-only authentication error Origin null is not allowed by Access-Control-Allow-Origin 如何使用Webworks修复Javascript(jquery)中的“ Access-Control-Allow-Origin不允许访问null的原始null”错误? - How do i fix “Origin null is not allowed by Access-Control-Allow-Origin” error in Javascript (jquery) with webworks?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM