【发布时间】:2025-12-30 09:15:13
【问题描述】:
我正在尝试使用开放天气 API 构建 5 天预报。我基于网站使用的参数不起作用,它返回未定义。另外,有什么方法可以让我从第 1 天、第 2 天等获得主要温度。请帮助
这是我的代码:
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/forecast', //API Call
dataType: 'json',
type: 'GET',
data: {
q: city,
appid: key,
units: 'metric',
cnt: '10'
},
success: function(data) {
var wf = '';
$.each(data, function(index, val) {
wf += '<p><b>' + data.city.name + '</b><img src=http://openweathermap.org/img/w/' + data.list[0].weather.icon + '.png></p>' + data.list[0].main.temp + '°C' + ' | ' + data.list[0].weather.main + ", " + data.list[0].weather.description
});
$("#showWeatherForcast").html(wf);
}
});
【问题讨论】:
标签: javascript ajax api openweathermap