JQuery.getJSON()读取本地文件 [英] JQuery.getJSON() reading a local file
问题描述
如何使用JQuery.getJSON()读取当前目录中的文件?
How do you read a file in the current directory using JQuery.getJSON()?
我正在尝试简单的事情(使用我的data.json文件)与我的html文件相同的目录):
I'm trying something simple (with my data.json file in the same directory as my html file):
$.getJSON("./data.json")
我收到错误:
XMLHttpRequest无法加载file:/// C:/Projects/test/data.json。 Access-Control-Allow-Origin不允许使用null。
XMLHttpRequest cannot load file:///C:/Projects/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin.
我尝试了各种路径组合,但它似乎不起作用...
I've tried all sorts of combinations of path, but it doesn't seem to work...
编辑:我正在使用Chrome,但我想在所有浏览器中工作......
I'm using Chrome, but I'd like to work in all browsers...
推荐答案
如果您使用的是谷歌浏览器,则有意在上的AJAX文件:///
路径永远不会有效。
If you are using Google Chrome, it is intentional that AJAX on file:///
paths never works.
这篇关于JQuery.getJSON()读取本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!