如何将从此json文件返回的项目推送到名为places:
的数组中var places = [];
$.ajax({
url: "http://www.example.com/places.json",
dataType: 'jsonp',
timeout: 5000,
success: function(data, status) {
$.each(data, function(i, item) {
places = item.latitude+','+ item.longitude;
});
},
error: function() {
$("#status").html('There was an error loading the data.');
}
});
答案 0 :(得分:2)
简单push
将数据放入数组中,如下所示:
places.push(item.latitude+','+ item.longitude);
答案 1 :(得分:0)
success: function(data, status) {
$.each(data, function(i, item) {
places.push( item.latitude+','+ item.longitude );
});
},
答案 2 :(得分:0)
尝试以下方法:
var places = [];
$.ajax({
url: "http://www.example.com/places.json",
dataType: 'jsonp',
timeout: 5000,
success: function(data, status) {
$.each(data, function(i, item) {
var place = item.latitude+','+ item.longitude;
places.push(place);
});
},
error: function() {
$("#status").html('There was an error loading the data.');
}
});