Queueing functions and Ajax in jQuery
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 hi开发者_运维百科deTable 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.
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 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
精彩评论