2015-08-15 14 views
6

Ich versuche eine Wetter App mit OpenWeatherMap API für Javascript zu erstellen. Der Code für meine Web-App ist:Wie OpenWeatherMap API für Javascript verwenden?

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

Was mache ich hier falsch?

+0

);} ist am Ende des Skripts fehlt –

Antwort

7

Sie haben parenthesis für getJSON Methode nicht abgeschlossen. Ansonsten habe ich einige Änderungen in Ihrem Code vorgenommen.

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