我正在尝试从同一文件夹中的JSON文件加载数据,这是我的javascript代码:
$.getJSON('JsonFile.json', function(data){
alert("here");
var a = data[0];
});
但是当我在chrome中打开这个html时,它会抛出错误:
XMLHttpRequest cannot load file:///C:/UserskkDesktopchartsJsonFile.json. Cross origin requests are only supported for HTTP. jquery.min.js:4
o.ajaxTransport.l.cors.a.crossDomain.send jquery.min.js:4
o.extend.ajax jquery.min.js:4
o.each.o.(anonymous function) jquery.min.js:4
o.extend.getJSON jquery.min.js:4
(anonymous function) chart.html:28
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/UserskkDesktopchartsJsonFile.json'. jquery.min.js:4
o.extend.ajax jquery.min.js:4
o.each.o.(anonymous function) jquery.min.js:4
o.extend.getJSON jquery.min.js:4
(anonymous function)
这显示我无法加载此JSON文件,任何人都知道原因,非常感谢