首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Jquery执行序列

Jquery执行序列
EN

Stack Overflow用户
提问于 2013-06-19 14:12:36
回答 1查看 48关注 0票数 0

我有一个向mvc控制器提交表单的函数,如下所示-

代码语言:javascript
运行
复制
function submitForm() {
            $.ajax
            ({
                type: 'POST',
                url: '/Users/Index',
                data: $('#searchForm').serialize(),
                beforeSend: function() { 
                    $('.usersearchresult').fadeOut('fast', function () { $('.loadinggif').show(); }); 
                    },
                success: function (response) {
                    $('.loadinggif').hide();
                    $('.usersearchresult').hide().html(response).fadeIn('normal');

                }
            });

            return false;
        }

这很好,除非响应返回得太快,$('.loadinggif').hide();$('.usersearchresult').hide().html(response).fadeIn('normal');之后发生$('.usersearchresult').hide().html(response).fadeIn('normal');

我尝试了不同的回调函数组合($('.loadinggif').hide();调用$('.usersearchresult').hide().html(response).fadeIn('normal'); on callback,甚至反过来调用,而且行为总是相同的)。

我对jquery并不熟悉;任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-19 14:17:50

问题是,如果响应返回得太快,fadeOut动画还没有完成。

要解决这个问题,请使用stop方法,它将结束动画:

代码语言:javascript
运行
复制
success: function (response) {
    $('.usersearchresult').stop();
    $('.loadinggif').hide();
    $('.usersearchresult').hide().html(response).fadeIn('normal');

}

请注意,stop将阻止调用回调,因此.loadinggif将永远不会显示响应是否在fadeOut动画仍在运行时返回。同时调用$('.usersearchresult').stop();$('.loadinggif').hide();是最简单的。它们是相互排斥的状态,因此您可以测试loadinggif是否显示并确定是否应该调用stophide

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17193543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档