As you have found, AJAX is asynchronous. It can be made synchronous, but you don't want to do that as it locks up the _entire_ browser.
The most common way to deal with this is to put up a "Loading" notice (sometimes using something like a modal overlay) while the data loads. Karl Rudd On Thu, Sep 4, 2008 at 8:53 AM, Bleys <[EMAIL PROTECTED]> wrote: > > Hi all, > > I have to execute an AJAX request in a function and only exit this > function when the request have been terminated. > This is an example : > function myFunction() > { > var result; > try > { > $.ajax({ > type: 'POST', > url: 'myPage.php', > ... > success: function(data){ > // do something with result > }, > error: function(){ > // do something else with result > } > }); > } > catch(e) > { > alert(e); > result = false; > } > return result; > } > > > As I think you can understand, I want to "return result" be executed > only when my success (or error) process have been terminated ... > > I tried to use async option but the result is the same, this is not > waiting for the end of the AJAX function. > I've find a solution but not very nice (an infinite "while" waiting > for a variable toggle to true) ... I hope better ... > > > Can I have some help please ? >