1

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.

dominik
  • 5,745
  • 6
  • 34
  • 45

2 Answers2

1

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
  • 83,000
  • 15
  • 95
  • 122
  • Thats a good answer. However, is there another without a callback? – dominik Nov 21 '09 at 16:25
  • That's by far the easiest solution. If you want to reuse the hidetable function, just pass in the callback as a parameter. – Nosredna Nov 21 '09 at 16:27
  • 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 Nov 21 '09 at 16:44
0

@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

Community
  • 1
  • 1
gpilotino
  • 13,055
  • 9
  • 48
  • 61