Wednesday 15 February 2012

jquery - GetJSON returns data asyncronously -



jquery - GetJSON returns data asyncronously -

i using code info database

var ourdata =''; $.getjson('getgaleri.php',function(data){ ourdata =data; }); //alert('loading'); }); html = html + '</ul></div></div>'; settimeout(function(){ $.each(ourdata, function(i, item) { html = html +"<li class='modern konserler'><a href='"+path+ourdata[i].resim_banner+"' rel='bookmark' class='fancybox'><img src='"+path+ourdata[i].resim_banner+"' alt='thememarket' /><div><span></span></div></a></li>"; $('#content').html(html); }, 4000);

to working need uncomment 4th line alert() , ourdata filled data, if didn't comment it, give nothing, ourdata empty string, thought using settimeout help didn't,

how prepare don't need alert() info filled in ourdata variable

that's because alert blocks thread long plenty getjson complete, after alert ourdata has been populated. utilize each within callback:

$.getjson('getgaleri.php',function(data){ $.each(data, function(i, item) { html = html +"<li class='modern konserler'><a href='"+path+data[i].resim_banner+"' rel='bookmark' class='fancybox'><img src='"+path+data[i].resim_banner+"' alt='thememarket' /><div><span></span></div></a></li>"; }); });

jquery ajax getjson

No comments:

Post a Comment