【问题标题】:How to use OpenWeatherMap API for Javascript?如何将 OpenWeatherMap API 用于 Javascript?
【发布时间】:2015-11-08 10:56:13
【问题描述】:

我正在尝试使用 OpenWeatherMap API for javascript 创建一个天气应用程序。我的网络应用程序的代码是:

<!DOCTYPE html>
<html> 
    <head>
        <title>Weather</title>
        <script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
        <script>
            function gettingJSON(){
                document.write("jquery loaded");
                $.getJSON("api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
                document.write(json);
            }
        </script>
    </head>
    <body>
        <button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
    </body>
</html>

我在这里做错了什么?

【问题讨论】:

  • );} 在您的脚本末尾丢失

标签: javascript weather-api openweathermap


【解决方案1】:

您还没有完成parenthesisgetJSON 方法。除此之外,我对您的代码做了一些修改。

<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
    function gettingJSON(){
        document.write("jquery loaded");
        $.getJSON("http://api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
            document.write(JSON.stringify(json));
        });
    }
    </script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>

http://jsfiddle.net/kqLeh3mz/

【讨论】:

    猜你喜欢
    • 2015-01-18
    • 2017-02-08
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多