javascript - Grabbing Values from a JSON API Responce, putting them into webpage -


today have question may seem kinda simple the rest of you. i'm learning how use apis/jsons , i'm little confused. i'm trying grab temperature openweathermap.org api response , displaying in html tag.

the javascript know grabbing temperature , setting var. i'm confused why cannot use id="" set text inside tag. code below have far. thank time.

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript"> var weather; var temp; $(document).ready(function() { $.ajax({     url: "http://api.openweathermap.org/data/2.5/weather?q=london,uk&appid=44db6a862fba0b067b1930da0d769e98&units=metric",     datatype: 'jsonp',     success: function(weather){     var temp = weather.main.temp; } });  </script> </head> <body> <p id="temp"></p> </body> </html> 

@arunpjohny have identified errors: 1) missing }) , 2) use $('#temp') html element. don't need declare weather because declared argument.

$(document).ready(function() {    $.ajax({      url: "http://api.openweathermap.org/data/2.5/weather?q=london,uk&appid=44db6a862fba0b067b1930da0d769e98&units=metric",      datatype: 'jsonp',      success: function(weather) {        $('#temp').text(weather.main.temp);      }    });  });
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>  <p id="temp"></p>


Comments