小编ork*_*rky的帖子

使用jQuery进行Forecast.io API使用

我在使用API​​创建完整的应用程序时遇到了一些问题,特别是Forecast.io weather api.为简单起见,我将我的JS直接放在我的HTML页面中.对于这个基本版本,我很高兴有这个展示的东西.假设我想要当前的温度(目前 - >温度).另外,我不确定"?回调?" 始终建议所有RESTful API使用.

<!DOCTYPE html>
<html>
    <body>  
    <p id="weather">Here's the weather:<p>

    <button onclick="b()">Submit</button>
        <script>

        function b(){

            var apiKey = '<private>';
            var url = 'https://api.forecast.io/forecast/';
            var lati = 0;
            var longi = 0;
            var data;

            $.getJSON(url + apiKey + "/" + lati + "," + longi + "?callback=?", function(data) {
              $('#weather').innerHTML('and the weather is: ' + data[4].temperature);
            });
        }
        </script>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

api jquery json weather-api

5
推荐指数
1
解决办法
6884
查看次数

标签 统计

api ×1

jquery ×1

json ×1

weather-api ×1