[英]How read json local file with jquery with ajax?
我只有js项目。 我从我的静态index.html文件中调用json文件内容。
我尝试(不起作用):
$.getJSON('/js/test.json&callback=?',
function() {
alert('1111111111111111');
},'jsonp');
修改chrome:XMLHttpRequest无法加载file:///somefolder/test/data.json。 Access-Control-Allow-Origin不允许使用原点null
谢谢
您可以从本地来源检索json,它不必是jsonp,即使它做了您在做什么也不是您如何做。
$.getJSON('http://yours.com/js/test.json',
function() {
alert('1111111111111111');
});
您在回调中缺少数据变量!
$.getJSON('/js/test.json', function(data) {
console.log('JSON data received:', data);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.