This is totally off the cuff and untested, but http://paste.pocoo.org/show/109610/
should work On Mar 25, 3:20 pm, Jsbeginner <jsbegin...@monarobase.net> wrote: > Hello, > > I've got a script that takes all the elements of a list and on click of > a button it runs an ajax query for each item. It all works fine however > I would like to have a "searching" message during the search and a > "finished" message after the search has finished, but I can't think how > to detect when the for cycle has finished and all ajax queiries ... > > Here's the code : > > > > > function checkall(){ > > $('#myform').submit(function() { > > $("#status").html("Searching"); > > $("#mylist>option").each(function(i){ > > lst[i] = $(this).val(); > > }); > > for ( var e in lst) { > > checkajax(lst[e]); > > } > > }); > > $("#status").html("Finished"); > > } > > > function checkajax(e){ > > $.ajax({ > > url : "/scripts/checkdata.php", > > type : "POST", > > data : "number="+e, > > dataType : "json", > > cache: false, > > error : function (xhr, desc, exception) { > > $("#status").html("Error");}, > > success : function (data) { > > > $(#mytable).append("<tr><td>"+data.id+"</td><td>"+data.name+"</td></tr>") > > } > > } > > }); > > } > > As you can guess the following line :> $("#status").html("Finished"); > > makes the status be finished before the ajax answers have been recieved... > > I would like to keep the ajax being asynchronous but detect when all the > queries sent by the "for" have finished and not when they have just been > sent ... > > Do you have any suggestions how I could achieve this ? > > Thankyou.