如何使用Javascript管理我的json内容
我想恢复json的内容,但我不能。控制台“say uncaughttypeerror:cannotreadproperty'longitude'of undefined”我对这个方法非常陌生。如果你能帮助我,谢谢你如何使用Javascript管理我的json内容,javascript,json,Javascript,Json,我想恢复json的内容,但我不能。控制台“say uncaughttypeerror:cannotreadproperty'longitude'of undefined”我对这个方法非常陌生。如果你能帮助我,谢谢你 var recuptable = []; $(document).ready(function(){ $.ajax({ url: 'http://******', type: 'get', dataType:
var recuptable = [];
$(document).ready(function(){
$.ajax({
url: 'http://******',
type: 'get',
dataType: 'JSON',
success: function(response){
recuptable.push(response);
}
});
});
console.log(recuptable[1].longitude);
代码是异步的,当控制台记录变量时,它仍然是空的。而是将console.log移到success函数中
var recuptable = [];
$(document).ready(function(){
$.ajax({
url: 'http://******',
type: 'get',
dataType: 'JSON',
success: function(response){
console.log(response.longitude);
recuptable.push(response);
}
});
});
另外,我建议您阅读一点有关回调和/或承诺的内容,以便能够更轻松地使用异步代码。请查看,这两个内容重复了哪一个。@DaveNewton为什么不将其标记为这样?:)好的,谢谢你,戴夫,我检查了@TylerRoper,因为这台机器上的快捷方式由于一个未知的原因失败了,在我意识到之前我已经离线了。好的,谢谢你,我明白了。