那么getJSon就不起作用了
getJSon then is not working
我正在尝试使用getJson函数从Json文件中获取数据:
$.getJSON( "uploads/data.json" ).then(function(data) {
allData = data.sculptures;
locations = {};
for(var i=0; i<data.location.length; i++) {
locations[data.location[i].name] = data.location[i].location;
}
console.log(allData);
console.log(locations);
});
但我什么都没得到。当我在Chrome控制台开发工具中运行此代码时,它只显示以下内容:
Object {}
always: ()
done: ()
fail: ()
pipe: ()
progress: ()
promise: (a)
state: ()
then: ()
__proto__: Object
这是data.json:
{"sculptures":[{"title":"Bust of Caracalla","location":"Paris"},
{"title":"Brutus The Younger","location":"Paris"}],
"location":[{"name":"Beaux-Arts in Dijon, France","location":{"lat":47,"lng":5}},
{"name":"Louvre, Paris","location":{"lat":48,"lng":2}},
{"name":"St Pauls Cathedral, London","location":{"lat":51,"lng":-0}},
{"name":"V&A, London","location":{"lat":51,"lng":-0}}]}
locations = [];
$.ajax({
type: "POST",
url: "uploads/data.json",
dataType: "json",
success: function(data) {
$(data.location).each(function(i, location){
locations[data.location[i].name] = data.location[i].location;
});
}
});
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- $.getJSON 在 Chrome 和 Safari 中不起作用
- 那么getJSon就不起作用了
- Javascript getJSON 不起作用(可能是跨域)
- getJSON 方法不起作用
- $.getJSON 在 IE10 中不起作用
- 为什么返回在getJSON中不起作用,为什么我不能从getJSON写入变量
- getJSON 在服务器上不起作用,但在本地工作
- $.getJSON没有'不起作用,但在脚本中包含JSON对象起作用
- 在pagebeforeshow中使用$.getJSON获取json数据在jquery mobile中不起作用
- 为什么我的$getjson电话不起作用
- getJson解析器没有'不起作用
- getJSON只响应明文,否则不起作用
- OpenWeatherMap.Org API - $.getJSON不起作用,我也没有接收到任何数据
- Getjson () jquery下拉菜单不起作用
- JSON_ENCONDE→getJSON不起作用
- PhoneGap中的$.getJSON不起作用
- $.getJSON不起作用