【发布时间】:2019-03-06 01:37:50
【问题描述】:
我正在尝试对 Openweathermap API 进行 ajax 调用,一旦函数离开 ajax,我的变量就不会更新。有人可以向我解释为什么我的 var tmp 没有更新。
var url1 = "http://api.openweathermap.org/data/2.5/find?lat=" + marker.position.lat()+"&lon="+marker.position.lng() + "&type=accurate&units=imperial&mode=json&APPID=8cbc2d4c3edf26435cf160f3cee969ed";
var tmp;
$.ajax({
type: 'get',
dataType: "jsonp",
url: url1,
async: false,
success:function (data) {
tmp =data.list[0].main.temp +"F " + data.list[0].weather[0].description;
console.log(tmp); //it logs correctly here
}
});
console.log(tmp); //it says it's undefined here
【问题讨论】:
标签: ajax api openweathermap