views:

112

answers:

3

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?

+3  A: 

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)
};
Chris Gutierrez
Perfect. I don't know why it seemed to work with the brackets in other places though... Maybe I just didn't notice it.
Hintswen
A: 

Move your function definitions outside of the load function. It should look like

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
}
stimms
ha! I knew that looked wrong, I actually got the code from somewhere else and couldn't figure out why they had it like that.
Hintswen
A: 

Try the following (wrap the call to sorter() in the load function in an anonymous function)

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