I came across this one. I have objects and I cycle the request to the server:

var obj=$("table tr"); obj.each(function(){ $.post("index.php",{$(this).attr("id")},function(data){ alert(data); }); }); 

How to achieve that the cycle did a delay yet did not receive the answer from the server? That is, the next cycle step is performed when a response is received from the server.

UPD.

Recursion?

Or how in that case $ .map () will behave?

UPD2

 var objs=$("table tr"); // length = 45 var i=0; function reload_all(obj){ if($(obj).attr("id")==undefined)return true; $(".reload_all_field").append($(obj).attr("id")+"|"+i+" "); i++; reload_all($(obj).next()); } reload_all(objs); // после обхода i = 38 вместо 44 

I did it this way, but out of 45 objects only 40 are processed. 5 pieces are skipped after the 5th. What is the problem? Can I use .next () for other purposes? ((

  • Make a cycle timer. And the time - how much you need. - koko
  • The timer does not fit, you need strictly on receipt of a response from the server. - Yoharny Babay 4:34 pm
  • Interesting, now I will try to implement. - Oleg
  • 2
    read the topic - slipped under the table =) thought the forum was wrong =) - Gorets
  • one
    there is generally a success that is triggered by server response - kemerov4anin

2 answers 2

All right you wrote above. Throw the code into the function and for success recursion. Or you can use deferred , but the meaning is about the same. See an example

  • Well, I don `t know ... Work, of course, an option. but I think the function will not find this object. Now check. - Yoharny Babay
  • this is not a global variable, if that ... So that there are no problems, make var someName = $ (this); and work on the variable someName without any problems - Deonis
  • I wrote what is happening with recursion ... - Yoharny Babay
  • one
    Well, here's another demo , in the example of @Deonis' and, like in my - this does not happen, respectively, cant in the code. - Zowie
  • @AlexWindHope I applied your function. It worked. Thank. For some reason, the example of @ Deonis didn’t work, I missed 5 pieces, as I said, even if there are 1000 objects. - Yoharny Babay

Something like this:

 var obj = $('table tr'), q = $.when(); obj.each(function () { q = $.when(q, $.post('index.php', { $(this).attr("id") })); }); d.done(function(){ alert(true); }); 

I did not check it, I never did it myself, I do not guarantee operability.