XMLHttpRequest:Origin-null不被Access-Control-Allow-Origin允许 [英] XMLHttpRequest: Origin null is not allowed by Access-Control-Allow-Origin

查看:1641
本文介绍了XMLHttpRequest:Origin-null不被Access-Control-Allow-Origin允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

XmlHttpRequest错误:原始null不被Access-Control-Allow-Origin所允许

XMLHttpRequest无法加载文件:// ... Origin null不是允许通过访问控制 - 允许来源


我试图打开我的JSON文件,例如:

  jQuery.getJSON('../ data / json / en / nodesData.json',











$ code>

这会在Chrome中产生以下错误:


XMLHttpRequest无法加载文件:/// C:/ URL /数据/ JSON / EN / nodesData.json。 Origin-null不允许被Access-Control-Allow-Origin


有什么问题?如何检索我的json?

解决方案

您真的应该运行本地服务器,如Apache或IIS来运行HTML / JavaScript代码所以你不会遇到这些限制。

你可以用标记 - 允许文件访问从文件启动浏览器,限制。

Possible Duplicate:
XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin
XMLHttpRequest cannot load file://… Origin null is not allowed by Access-Control-Allow-Origin

I am trying to open my JSON file such as:

jQuery.getJSON('../data/json/en/nodesData.json',
      function(data){
           jQuery.each(data, function(){
                  //do something...
           })
     })

this yields the following error in Chrome:

XMLHttpRequest cannot load file:///C:/URL/data/json/en/nodesData.json. Origin null is not allowed by Access-Control-Allow-Origin

what's problem? How can I retrieve my json?

解决方案

You really should be running a local server like Apache or IIS to run HTML/JavaScript code so you do not run into these restrictions.

You can start the browser up with the flag --allow-file-access-from-files which removes the restriction.

这篇关于XMLHttpRequest:Origin-null不被Access-Control-Allow-Origin允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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