I suggest looking at one of the Ajax helper plugins, such as: http://plugins.jquery.com/project/AjaxManager
If you want to DIY you'll need to either build some sort of "queue" or nest the validation You could also try the validation plugin ( http://plugins.jquery.com/project/validate ) which has a "remote" option. Karl Rudd On Fri, Mar 13, 2009 at 10:25 AM, Andy789 <e...@abcstudio.com.au> wrote: > > Hi All, > > Here is a simple fragment: > > function zipSearch(){ > var zip = $j('input#zip_entry').attr('value'); > validateZip(zip); > alert('second '+validation); > ........... > ............ > } > > function validateZip(zip){ > $j.post("markers.php", { validate: zip}, > function(xml){ > validation = $j.xml2json(xml, false); > alert('first '+validation); > }); > } > > The problem is that the first function (zipSearch) calls validateZip > and doesn't wait until it gets callback data from php file. So it > jumps to the next line. I am getting 1st alert ('second '+validation) > and next the alert from ajax function. > > How can I fix it to make sure the first function waits until > validateZip gets its callback? > > thanks!