2015-08-15 3 views
6

Я пытаюсь создать приложение погоды с API OpenWeatherMap для javascript. Код для моего веб-приложения:Как использовать API OpenWeatherMap для Javascript?

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

Что я здесь не так?

+0

);} отсутствует в конце сценария –

ответ

7

Вы не заполнили parenthesis по телефону getJSON. Кроме этого, я сделал несколько изменений в вашем коде.

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

 Смежные вопросы

  • Нет связанных вопросов^_^