tags:

views:

80

answers:

2

Hello, I've got two functions and one problem.

hideTable();
ajaxCall(params);

The function hideTable

function hideTable() {
    if (effects) {
     $('#jquerytable tbody').fadeOut(speed);
    }
}

I want the ajaxCall function to be executed after the hideTable function (which takes a little time). The showTable function should be executed after the ajax call. I tried a lot but nothing worked fine for me. The Ajax call starts before the hideTable function is finished. I think I could use the jQuery queue but I don't know how to apply it to this problem.

By the way, I don't want to use a callback function beacause I want to reuse the hideTable function in other contexts.

Would be nice if you could help me out.

+1  A: 

jQuery's animate and hide functions have callbacks you can use.

animate( params, [duration], [easing], [callback] )
hide( speed, callback )

So what is the code for hideTable? Does it use $().hide() ? If so, set the callback to be your ajax function

Nosredna
Thats a good answer. However, is there another without a callback?
dominik
That's by far the easiest solution. If you want to reuse the hidetable function, just pass in the callback as a parameter.
Nosredna
There are many other (less desirable) was to solve the problem. You could have a global variable keep track of the state of the table (hidden, animating, shown). Of course, you'd be using the callback to update the global from animating to hidden.
Nosredna
A: 

@nosredna answer to use callbacks is the way to go but if you want do do it with jquery queue i suggest you to look at this answer to a similar question

gpilotino