![](/img/trans.png)
[英]Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
[英]Origin http://localhost is not allowed by Access-Control-Allow-Origin with xui.js
嗨,我想用xhr在xui中获取一个json文件,我的代码是这样的:
function getRequest()
{
x$().xhr('http://localhost:8080/DummyServer/login/request/',
{
callback: function()
{
saveLocalStorage(this.responseText);
},
});
}
我通过Safari控制台进行了检查,但出现了这样的错误:
XMLHttpRequest cannot load http://localhost:8080/DummyServer/login/request/. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
但是当我使用coda ide时没有错误,我想知道为什么。 有人可以帮我这个xui.js吗?
浏览器强制执行相同的来源策略,以保护网站免受其他提出xhr请求并显示其内容的网站的影响,就像它们是自己的一样。
因此,站点A.com无法使用XHR连接到B.com或: http : //A.com无法连接到http://sub.A.com localhost:80无法连接到localhhost:8080
解决此问题的一种方法是使用JSONP或CORS标头,但IE <10中不支持CORS。
最终,我可以使用chrome做到这一点,并通过使用以下方法打开chrome来禁用AJAX的跨域安全检查:/ Applications / Google \\ Chrome.app/Contents/MacOS/Google \\ Chrome --disable-web-security(在Windows),所有功能运行时都不会出现任何错误以获取详细信息: http : //opensourcehacker.com/2010/11/29/disabling-cross-domain-security-check-for-ajax-development-in-google-chrome/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.