最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

weather api - How to use OpenWeatherMap API for Javascript? - Stack Overflow

programmeradmin4浏览0评论

I am trying to create a weather app with OpenWeatherMap API for javascript. The code for my web app is :

<!DOCTYPE html>
<html> 
    <head>
        <title>Weather</title>
        <script src = ".6.2.min.js"></script>
        <script>
            function gettingJSON(){
                document.write("jquery loaded");
                $.getJSON("api.openweathermap/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?

I am trying to create a weather app with OpenWeatherMap API for javascript. The code for my web app is :

<!DOCTYPE html>
<html> 
    <head>
        <title>Weather</title>
        <script src = "http://ajax.aspnetcdn./ajax/jQuery/jquery-1.6.2.min.js"></script>
        <script>
            function gettingJSON(){
                document.write("jquery loaded");
                $.getJSON("api.openweathermap/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?

Share Improve this question edited Nov 10, 2017 at 5:34 yPhil 8,3775 gold badges61 silver badges91 bronze badges asked Aug 15, 2015 at 7:53 ArjunArjun 1,3551 gold badge12 silver badges28 bronze badges 1
  • );} is missing at the end of your script – Bertrand Martel Commented Aug 15, 2015 at 8:09
Add a ment  | 

1 Answer 1

Reset to default 9

You have not pleted parenthesis for getJSON method. Other than that I made few modification in your code.

<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
    function gettingJSON(){
        document.write("jquery loaded");
        $.getJSON("http://api.openweathermap/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/kqLeh3mz/

发布评论

评论列表(0)

  1. 暂无评论