Get data from json web service using only JavaScript and jQuery -


i have downloaded sample application using url http://www.zachhunter.com/2010/04/json-objects-to-html-table/. part working :

<script src="scripts/jquery-1.3.2.debug.js" type="text/javascript"></script> <script src="scripts/json.htmtable.js" type="text/javascript"></script> <script src="scripts/json.debug.js" type="text/javascript"></script> <link href="styles/default.css" rel="stylesheet" type="text/css" />  <script type="text/javascript">     $(document).ready(function () {         /* assoc array - detail view */         var json1 = { "d": [{ "__type": "acation", "id": "001", "date": "2010-06-01                       00:00:00", "iod": "1", "mer": "abc ", "tity": "6", "ot":                        "12,500", "nt": "75000", "ou": "a", "rep": "we", "perc": "34",                        "ine": "one", "year": "2009", "ct": "abc ", "alet": "90000",                         "pro": "1500", "stats": "ive", "crnt": "5000", "ter": "aa"}] }          /* normal array - detail view */         var json2 = { "d": [{ __type: "acation", id: "001", date: "2010-06-01                        00:00:00", iod: "1", mer: "abc ", tity: "6", ot: "12,500", nt:                        "75000", ou: "a", rep: "we", perc: "34", ine: "one", year:                        "2009", ct: "abc ", alet: "90000", pro: "1500", stats: "ive",                        crnt: "5000", ter: "aa"}] }          /* normal array - table view */         var json3 = { "d": "[{\"id\":1,\"username\":\"sam smith\"},{\"id\":2,\"username                       \":\"fred frankly\"},{\"id\":1,\"username\":\"zachary                        zupers\"}]" }          $('#dynamicgridloading').hide();          delete json1.d[0]["__type"];         delete json2.d[0]["__type"];          $('#dynamicgrid').append(createdetailview(json1.d, "lightpro", true)).fadein();         $('#dynamicgrid').append(createdetailview(json2.d, "lightpro", true)).fadein();         $('#dynamicgrid').append(createtableview(json3.d, "lightpro", true)).fadein();      }); </script>  </head>  <body>    <form id="form1" >    <div id="dynamicgrid" >      <div id="dynamicgridloading" >         <img src="images/loading.gif" /><span> loading data... </span>      </div>    </div>   <br />   <a href="jsonservice_api.html">json web service</a>   </form>  </body> 

its working fine, when try use free json webservice weather api: http://api.worldweatheronline.com/free/v1/weather.ashx?q=dehradun&format=json&num_of_days=5&key=3tkb34yntmwqn23uambzdvgm in following way getting nothing.

  <script type="text/javascript">     $(document).ready(function () {         $.ajax({             type: "get",             url: "http://api.worldweatheronline.com/free/v1/weather.ashx?q=dehradun&                   format=json&num_of_days=5&key=3tkb34yntmwqn23uambzdvgm",             contenttype: "application/json; charset=utf-8",             datatype: "json",             data: "{}",             success: function (res) {                 $('#dynamicgrid').append(createtableview1(res, "cooltabletheme",                                      true)).fadein();             }         });     });  </script> 

the definition createtableview in 1 of js file included in scripts tag having definition follows :

function createtableview(objarray, theme, enableheader) {   // set optional theme parameter   if (theme === undefined) {       theme = 'mediumtable'; //default theme   }    if (enableheader === undefined) {       enableheader = true; //default enable headers   }    var array = typeof objarray != 'object' ? json.parse(objarray) : objarray;    var str = '<table class="' + theme + '">';    // table head   if (enableheader) {       str += '<thead><tr>';       (var index in array[0]) {           str += '<th scope="col">' + index + '</th>';       }       str += '</tr></thead>';   }    // table body   str += '<tbody>';   (var = 0; < array.length; i++) {       str += (i % 2 == 0) ? '<tr class="alt">' : '<tr>';       (var index in array[i]) {           str += '<td>' + array[i][index] + '</td>';       }       str += '</tr>';   }   str += '</tbody>'   str += '</table>';   return str; 

}

please me urgent.... in advance.

what trying metwit weather api?
here working , simple jquery example : http://jsbin.com/isukam/1

check weather resource more information.

disclosure: own api.


Comments