i'm trying values json file, data stored in form of array.. here code:
js:
var initdate = new date("7/9/2013"); var diffdays = 0; var times; function taqvimsingledate() { // calculation of dates difference var currdate = new date(); diffdays = math.floor((currdate.gettime() - initdate.gettime()) / (1000 * 60 * 60 * 24)); $.getjson('alldata.json', function(data) { if (data != '' || data != undefined) { var addtohtml = ''; addtohtml += '<td>' +data[diffdays].date_g+ '</td>'; $('#singledate').html(addtohtml); // display appropriate time according location (01 or 02 etc.) switch(getcity) { case '01': $('#sahari').html(data[diffdays].sahar_1); times = data[diffdays].sahar_1; break; case '02': $('#sahari').html(data[diffdays].sahar_2); times = data[diffdays].sahar_2; break; case '03': $('#sahari').html(data[diffdays].sahar_3); times = data[diffdays].sahar_3; break; case '04': $('#sahari').html(data[diffdays].sahar_4); times = data[diffdays].sahar_4; break; } } else {alert("database undefined/empty!");} }); } alert(times);
the result of element #sahari
correct displayed (according value of getcity), problem times
variable undefined , i'm stuck here. how pass value of #sahari
correctly times
variable?
actually, value stored in times
, cannot use @ point in time. available after callback went through sucessfully. call function processing desired variable within callback function , able access times
.
Comments
Post a Comment