Tuesday, 15 February 2011

php - How to know when Ajax function is complete and all affected elements fully loaded? -



php - How to know when Ajax function is complete and all affected elements fully loaded? -

i have next code (amount other things) gets image url server:

$.ajax({ url: 'script.php', data: {action: 'random'}, type: 'post', datatype: "html", success: function(data) { var results = data.slice(0,-1).split('|'); var workers = []; for(i=0; i<results.length; i++) { workers[i] = workers[i].split(','); } for(i=0; i<workers.length; i++) { var j = i+1 $('#random-worker' + j + '-pic').attr("src", workers[i][3]); $('#random-worker' + j + '-name').html(workers[i][0]); $('#random-worker' + j + '-pro').html(workers[i][1]); $('#random-worker' + j + '-city').html(workers[i][2]); } } });

also, have code display loading gif while ajax requests process

var $loading = $('.div-loading').hide(); $(document) .ajaxstart(function () { $loading.show(); }) .ajaxstop(function () { $loading.hide(); });

what happens ajax completed , $loading div hidden , elements gets values , image gets new source. there way end loading process , hide $loading div?

thanks.

php jquery html ajax

No comments:

Post a Comment