【发布时间】:2017-11-06 03:07:51
【问题描述】:
我继续使用codepen:jQuery.Deferred exception: Cannot read property '0' of undefined" "TypeError: Cannot read property '0' of undefined 在控制台上收到此消息。
我的 javascript 代码:
var api_key = "fa15d403d0ab55e3cfd6e0867bbb0114";
$(document).ready(function(){
var loc;
//Call the location
$.getJSON('https://ipinfo.io', function(data){
loc = data.loc.split(",");
console.log(loc);
});
$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + loc[0] + '&lon=' + loc[1] + '&APPID='+ api_key, function(weather){
console.table("c ,",weather);
});
});
【问题讨论】:
-
当
console.log(loc);时你在控制台看到了什么 -
'''loc' 表示位置,所以它控制台记录纬度和经度。