Sunday, 15 September 2013

jquery each loop with ajax differently result -



jquery each loop with ajax differently result -

$('.body').find('.entry').each(function () { console.log('div found'); var = $(this); $.get('recommends').done(function(html) { that.append(html); console.log('appended'); }); });

in chrome console

(2) div found

(2) appended

i want result below, helps?

div found

appended

div found

appended

i think chrome grouping message seek add together index number maessages--but not main reason

var i= 0; $('.body').find('.entry').each(function () { console.log('div found'+window.i); var = $(this); $.get('recommends').done(function(html) { that.append(html); console.log('appended'+window.i); }); });

also, might because of how ajax works it's async, loop asks phone call start, while done phone call function executes when ajax info received

for illustration you've 2 children , tell each 1 of them go grab me orange tell kid 1 kid two, foreach when each 1 of children done orange done callback do

the foreach won'twait finish work

jquery

No comments:

Post a Comment