首页 > 解决方案 > OpenWeatherMap API 调用“图标”不起作用

问题描述

我正在尝试进行 ajax 调用以显示当前天气信息,但是,只有“图标”没有显示。所有其他项目都工作得很好。

function APIcalls() {

    // URL to make API calls for current forecast
    let currentForeCastUrl = "https://api.openweathermap.org/data/2.5/weather?q=" + 
                                city + "&appid=0fb779217270dc1943ca287687bf9395";
    
    $.ajax({
        url: currentForeCastUrl,
        method: "GET",
    }).then(function (response) {
        
        let temp = Math.round(((response.main.temp - 273.15) * 9 / 5 + 32));
        $("#icon").attr("src", "http://openweathermap.org/img/w/" + response.weather[0].icon + ".png");
        
    });

}

标签: ajaxapiicons

解决方案


推荐阅读