Load local JSON files via file:// triggers cross-domain null origin violation, solution? (jQuery)

好久不见. 提交于 2020-01-10 04:06:09

问题


I have a webpage I'd like to use locally, without a web server, by simply opening the local HTML file in my browser. This webpage in question loads data via jQuery's getJson() method, as in:

$.getJSON("mydata.json", function(j) { 
...

The JSON files are also local, and are stored in the same directory as the webpage. When I attempt to use the page, I get:

Origin null is not allowed by Access-Control-Allow-Origin.

(Chrome 6 OS X, similar errors in Firefox and Safari).

Is there any way around this? Is it possible to load JSON from local files? Thanks!


回答1:


Try running Chrome with --allow-file-access-from-files.



来源:https://stackoverflow.com/questions/3851691/load-local-json-files-via-file-triggers-cross-domain-null-origin-violation-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!