【问题标题】:how to stop callback until Animations in ajax beforeSend event have completed?如何停止回调,直到 ajax beforeSend 事件中的动画完成?
【发布时间】:2010-08-22 21:14:42
【问题描述】:

我在 beforeSend ajax 事件中使用 slideUp 和 slideDown 工作正常是 firefox,但在其他浏览器中,ajax 回发似乎在 slideUpDown 完成之前完成,所以我的成功函数首先执行,然后是 slideUp/Down。

如何将其更改为 (1) 在上滑/下滑完成之前不发送 ajax 或 (2) 在上滑/下滑完成之前不处理成功函数中的结果?

我尝试创建一个 isAnimationFinished 变量,该变量在 slideDown 完成并且成功时设置,我有一个空的 while 循环等待这个变量,但是如果我尝试这个,我会收到一个关于脚本运行缓慢的错误。

【问题讨论】:

    标签: jquery ajax


    【解决方案1】:

    没有看到您的代码,我不确定每个函数在做什么。我最初的想法是将slide函数与ajax调用分开,这样ajax函数只在slide函数完成后运行。

    如果这不合适,请发布一些我们可以解决的代码。谢谢!

    【讨论】:

    • 谢谢,我最终采用了这种方法。 beforeSend 事件不适合我的需要。
    【解决方案2】:
    $.ajax({
            url: pageurl + "?data-role=button",
                                                beforeSend: function(){
                                                    console.log('beforesend');
                                                    animationBeforesend(); // loading bar
                                                },
                                                complete: function(){
                                                    console.log('Compelete');
                                                },
            success: function (data) {
                                                    var totalTime = new Date().getTime()-ajaxTime;
                                                    console.log(totalTime + ' micro second page loading time');
                                                    console.log('Success');
                                                    console.log($('#progressbar').attr('value'));
                                                    $(".Sitecontainer").html(data);
                                                    loadFunction(); // loading bar HIDE
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2011-07-09
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2012-04-19
      • 2011-07-10
      • 2019-11-27
      • 1970-01-01
      相关资源
      最近更新 更多