Wait for function to finish before executing the rest
        Posted  
        
            by Wurlitzer
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Wurlitzer
        
        
        
        Published on 2010-04-25T21:50:23Z
        Indexed on 
            2010/04/25
            21:53 UTC
        
        
        Read the original article
        Hit count: 245
        
JavaScript
|jQuery
When the user refreshes the page, defaultView() is called, which loads some UI elements. $.address.change() should execute when defaultView() has finished, but this doesn't happen all the time. $.address.change() cannot be in the success: callback, as it's used by the application to track URL changes.
defaultView();
function defaultView() {
    $('#tout').fadeOut('normal', function() {
        $.ajax({
            url: "functions.php",
            type: "GET",
            data: "defaultview=true",
            async: false,
            success: function (response) {
                $('#tout').html(response).fadeIn('normal');
            }
        });
    });
}
$.address.change(function(hash) {
    hash = hash.value;
    getPage(hash);
});
I'm at a loss as to how to make $.address.change() wait for defaultView() to finish. Any help would be appreciated.
© Stack Overflow or respective owner