简体   繁体   English

如何使用OpenWeatherMap API for Javascript?

[英]How to use OpenWeatherMap API for Javascript?

I am trying to create a weather app with OpenWeatherMap API for javascript. 我正在尝试使用OpenWeatherMap API为javascript创建一个天气应用程序。 The code for my web app is : 我的网络应用程序的代码是:

<!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>

What am I getting wrong here? 我在这里弄错了什么?

You have not completed parenthesis for getJSON method. 您还没有完成getJSON方法的parenthesis Other than that I made few modification in your code. 除此之外,我在你的代码中做了一些修改。

<!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/ http://jsfiddle.net/kqLeh3mz/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM