[英]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.