XMLHttpRequest无法加载。? [英] XMLHttpRequest cannot load.?

查看:97
本文介绍了XMLHttpRequest无法加载。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 chrome-> Inspect element-> console 得到此错误:


XMLHttpRequest无法加载。
Access-Control-Allow-Origin不允许原点。

XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin.

这解决了什么?

推荐答案

您不能通过XMLHttpRequest向其他域或子域发出请求。
如果您要从www.foo.com发出请求,您还需要在www.foo.com上定位请求,而不是遗漏www。

You cannot issue requests through the XMLHttpRequest to other domains or subdomains. If you are issuing the request from www.foo.com you also need to target the request at www.foo.com and not leave out the www.

如果您确实需要访问另一个域,可以使用 JsonP 浏览器使用< script> 标记从其他域加载脚本的功能。然后加载的脚本执行回调函数来为您提供数据。但是对于常规的AJAX调用,你根本不能离开源域。

If you really need to hit another domain you can use JsonP where the browser utilizes the <script> tags ability to load scripts from a different domain. The loaded script then executes a callback function to give you the data. But for regular AJAX calls you cannot leave the source domain at all.

请参阅同源政策

这篇关于XMLHttpRequest无法加载。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆