开发者

How can I delay an ajax call in jQuery?

Is there a way to del开发者_StackOverflow社区ay an ajax request from executing until an animation finished?

var showAjaxLoader = function(selector) {
    $("." + selector).fadeToggle("slow");
    $("." + selector).parent().html('<img src="ajax-loader.gif" />').fadeIn();
};

$(".add, .delete")
    .bind("ajax:beforeSend", function(event, data, status, xhr) {
        showAjaxLoader(this.className);
});

Basically, the response of the request will replace the lay contents, but I don't want this to happen until the effect took place. Otherwise the image will just pop up with no effect...


U can use a callback methode for when the animation is finished:

$("p").fadeToggle("slow", function () {
   $("div").append("<div>finished animation</div>");
   // Here you can put your ajax request
});


Just use callback, as in the .fadeToggle(), .fadeIn() and .fadeOut() documentation. Make AJAX call within this callback.

And I believe you do not want to make request even when fading out that box (at least I don't see the reason here), but only when fading in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜