jquery - Issue with calling multiple JSON files -
so have looked around , found information on how call 2 json files using jquery. while able call both files getting following error: var weather = data.data.weather;
if comment out 1 of variables (dataurl2) calls in json file works no problem. below sample of js
var zipcode = '27560'; var appid = '96afa96cadeb7165258ae95b77fdc'; var startdate = '2015-10-01'; var enddate = '2015-10-31'; var timeperiod ='24'; var dataurl = '//api.worldweatheronline.com/premium/v1/past-weather.ashx?q='+ zipcode +'&format=json&date='+ startdate +'&enddate='+ enddate +'&tp='+ timeperiod +'&key='+ appid var dataurl2 = '//westbrookfl.com/wp-content/plugins/csanalytics/lib/data/data-channeldata.php' //creates table citation data jquery.when( jquery.getjson(dataurl), jquery.getjson(dataurl2) ).then(function (data, datatwo) { console.log(data, datatwo); var citationhtml = ''; jquery.each(data, function (i) { var weather = data.data.weather; (var = 0; < weather.length; ++i) { citationhtml += '<li id="day'+[i]+'" class="day"><div class="date">' + weather[i].date + '</div><div class="svg-icon"><img src="' + weather[i].hourly[0].weathericonurl[0].value + '" /></div><div class="data-wrap col2"><p class="data hi-temp"><span>' + weather[i].maxtempf + '</span><sup class="deg ng-scope" data-ng-if="hasvalue()">°</sup></p><p class="data lo-temp"><span>' + weather[i].mintempf + '</span><sup class="deg ng-scope" data-ng-if="hasvalue()">°</sup></p></div><p class="data desc">' + weather[i].hourly[0].weatherdesc[0].value + '</p></li>'; } }); jquery('#citation_report').append(citationhtml); });
here fiddle well: https://jsfiddle.net/joseph_a_garcia/s41kr5hj/1/
any appreciated.
here working demo.
js
var zipcode = '27560'; var appid = '96afa96cadeb7165258ae95b77fdc'; var startdate = '2015-10-01'; var enddate = '2015-10-31'; var timeperiod ='24'; var dataurl = '//api.worldweatheronline.com/premium/v1/past-weather.ashx?q='+ zipcode +'&format=json&date='+ startdate +'&enddate='+ enddate +'&tp='+ timeperiod +'&key='+ appid var dataurl2 = '//westbrookfl.com/wp-content/plugins/csanalytics/lib/data/data-channeldata.php' //creates table citation data $.when( $.getjson(dataurl), $.getjson(dataurl2) ).done (function (data, data2) { var data = data[0].data; console.log(data); var citationhtml = ''; jquery.each(data, function (i) { var weather = data.weather; (var = 0; < weather.length; ++i) { citationhtml += '<li id="day'+[i]+'" class="day"><div class="date">' + weather[i].date + '</div><div class="svg-icon"><img src="' + weather[i].hourly[0].weathericonurl[0].value + '" /></div><div class="data-wrap col2"><p class="data hi-temp"><span>' + weather[i].maxtempf + '</span><sup class="deg ng-scope" data-ng-if="hasvalue()">°</sup></p><p class="data lo-temp"><span>' + weather[i].mintempf + '</span><sup class="deg ng-scope" data-ng-if="hasvalue()">°</sup></p></div><p class="data desc">' + weather[i].hourly[0].weatherdesc[0].value + '</p></li>'; } }); jquery('#citation_report').append(citationhtml); });
note: weather
object reference not correct in codes. have added line var data = data[0].data;
, it's working fine! can second getjson data in data2
variable if want use that!
Comments
Post a Comment