$ .getJSON无法使用本地JSON文件 [英] $.getJSON not working with local JSON file
本文介绍了$ .getJSON无法使用本地JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我拼命想要获得一个网站的本地版本来获取JSON文件(也是本地文件)而没有运气。确切的代码在我的服务器上工作得很好,但是一旦在本地,就会中断。
I am desperately trying to get a local build of a site to get a JSON file (also local) with no luck. The exact code worked perfect on my server, but once local, breaks.
我用jQuery得到了JSON,如下所示:
I get the JSON with jQuery like so:
$.getJSON(
"lib/js/app.json",
function(data){
$.each(data, function(i,user){
+'<img src="'+user.thumbnail+'"/>
});
}
);
收到此控制台错误:
XMLHttpRequest cannot load file://localhost/Users/blakestruhs/new/lib/js/app.json. Origin null is not allowed by Access-Control-Allow-Origin.
我很想回答这里的答案。请帮助我。
I'm dying for an answer here. Please help me.
推荐答案
我认为你使用像Chrome这样的Webkit浏览器,对吗? Chome看不到两个本地文件之间的关系。使用Firefox或在网络服务器上运行;)
I think you use a Webkit browser like chrome, right? Chome does'n see a relation between two local files. Use Firefox or run it on a webserver ;)
Access-Control-Allow-Origin不允许原点为空。在Chrome中。为什么?
这篇关于$ .getJSON无法使用本地JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文