Advertisement
Guest User

apiweather.html

a guest
Apr 24th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.72 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Learning JQUERY API</title>
  5. </head>
  6. <body>
  7.      
  8.     <div id='infoSummary'>
  9.    
  10.     </div>
  11.    
  12.     <div id='infoDetails'>
  13.    
  14.     </div>
  15.  
  16.  
  17.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  18.     <script>      
  19.         serviceLocation = "http://api.worldweatheronline.com/free/v2/weather.ashx";
  20.         key = "b4c0094fbfe03d010d386b5f41c9e";
  21.        
  22.  
  23.         myQuery = {};
  24.         myQuery.format = "json";
  25.         myQuery.q = "London";
  26.         myQuery.num_of_days = "1";
  27.         myQuery.date = "today";
  28.        
  29.        
  30.         req = serviceLocation + "?";
  31.         $.each(myQuery, function (k, v) {
  32.             req += k + '=' + v + '&';  
  33.         });  
  34.  
  35.         req += 'key' + '=' + key;
  36.        
  37.         $(document).ready(function (){
  38.  
  39.             $.getJSON(req, function (res){
  40.  
  41.                 var weatherIconUrl = res.data.current_condition[0].weatherIconUrl[0].value;              
  42.                 var observation_time = res.data.current_condition[0].observation_time;
  43.                 var temp_C = res.data.current_condition[0].temp_C;
  44.                 var cloudcover = res.data.current_condition[0].cloudcover;
  45.                
  46.  
  47.                 $('#infoSummary').html('<img src="' + weatherIconUrl + '" height="342" width="342">');            
  48.                 $('#infoDetails').html(
  49.                     "At the time <b>" + observation_time + "</b>" +
  50.                            " the " + myQuery.q + " temperature was <b>" + temp_C + " &deg;C </b>" +
  51.                            " with cloud cover of <b>" + cloudcover + "%</b>.");            
  52.             });
  53.         });      
  54.     </script>
  55.    
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement