How to use OpenWeatherMap API for Javascript?

I am trying to create a weather application with the OpenWeatherMap API for javascript. Code for my web application:

<!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 doing here?

+5
source share
1 answer

You did not perform parenthesis for the getJSON method. Other than that, I made a few changes to 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/

+6
source

All Articles