正如标题所说,我正在尝试制作一个天气应用程序,它可以获取用户的位置并获取他们本地的天气。我陷入了第二个无法执行的函数和 console.log(); 上不提供任何输出。任何帮助将不胜感激。
$(document).ready(function () {
function getLocation() {
$.getJSON("http://ipinfo.io", function (response) {
var cc = response.country;
var city = response.city;
var state = response.region;
$(".city").html(city + "," + state);
console.log(cc);
var url = "api.openweathermap.org/data/2.5/weather?q=" + city + "," + cc + "&APPID=1d0e324c03cd19ecf0abf20ac2708666";
console.log(city);
console.log(url);
getWeather(url);
});
}
function getWeather(url) {
$.getJSON(url, function (response) {
console.log(url);
$(".temp").html(Math.round(response.main.temp));
});
}
getLocation();
});
最佳答案
按如下方式更改网址:
var url = "http://api.openweathermap.org/data/2.5/weather?q="+city+","+cc+"&APPID=1d0e324c03cd19ecf0abf20ac2708666";
你缺少http
关于javascript - getJSON 未执行的第二个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41995327/