Search code examples
jqueryjquery-callback

jQuery callback called too early?


Here's the code I'm using:

function load(toLoad, area){
    $(area).html('<img src="images/ajax-loader.gif" alt="Loading" class="center" />');
    loadContent();
    function loadContent() {
        $(area).load(toLoad,'',sorter())
    };
    function sorter() {
        alert('s');
        $("#myTable").tablesorter({
            widgets: ['zebra']
        });
    };
    return false
};

When the load function is called, the alert shows when the loading image is shown, rather than after it has finished loading.

What is wrong with it?


Solution

  • I think the syntax is a little off for this.

    instead of

    function loadContent() {
        $(area).load(toLoad,'',sorter())
    };
    

    try

    function loadContent() {
        $(area).load(toLoad,'',sorter)
    };