0

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?

Hintswen
  • 3,987
  • 12
  • 40
  • 45

3 Answers3

5

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
  • 4,750
  • 19
  • 18
  • 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 Nov 15 '09 at 23:59
0

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
  • 42,945
  • 30
  • 96
  • 149
  • 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 Nov 15 '09 at 23:58
0

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
  • 117
  • 5