Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OpenWeatherMap API for Javascript?

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.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?

like image 401
Arjun Avatar asked Aug 15 '15 07:08

Arjun


People also ask

How do I make an OpenWeather API call?

The API key is all you need to call any of our weather APIs. Once you sign up using your email, the API key (APPID) will be sent to you in a confirmation email. Your API keys can always be found on your account page, where you can also generate additional API keys if needed.

Is OpenWeatherMap a REST API?

5. [This API has been deprecated and replaced by the Current Weather Data, 5 Day Weather Forecast, 16 Day Weather Forecast, Historical Data, History Bulk, Weather Map Layers, Ultraviolet Index, Weather Stations, Weather Alerts, Air Pollution, and Accumulated Weather Data APIs.

What type of API is OpenWeatherMap?

As a start to use OpenWeather products, we recommend our One Call API 3.0. For more functionality, please consider our products, which are included in professional collections.


1 Answers

You have not completed 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.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/

like image 145
Darshan Patel Avatar answered Oct 13 '22 19:10

Darshan Patel