XMLHttpRequest:Origin-null不被Access-Control-Allow-Origin允许 [英] XMLHttpRequest: Origin null is not allowed by 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屋!