我在Ajax成功回调中将jQuery .fade()函数放在哪里? [英] where do i put jQuery .fade() function in ajax success callback?

查看:92
本文介绍了我在Ajax成功回调中将jQuery .fade()函数放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ajax调用,该页面用成功回调中返回的html填充页面的一部分:

I have an ajax call that is populating a portion of my page with the html it returning in the success callback:

function LoadCurrentCourses(masterKey, status) {
status = 'S';
$.ajax({
    type: "GET",
    url: "/Home/LoadCurrentCourses/?masterKey=" + masterKey + "&status=" + status,
    dataType: "html",
    success: function (evt) {
        $('#currentCourses').fadeIn(1500, function () { $('#currentCourses').html(evt) });
    },
    error: function (req, status, error) {
        $('#currentCourses').html("<p>Error occured retrieving current courses</p>");
    }
});

}

#currentCourses标记只有一个标头并在其中加载.gif.

the #currentCourses markup just has a header and loading .gif in there.

<div class="span4 moduleBox" id="currentCourses">
    <h2>Current Courses</h2>
    <img style="margin-left: 45%; margin-top: 5%; margin-bottom: 5%;" src="~/Images/11.gif" />
</div>

我在doc.ready()的主页上调用了ajax:

The ajax is being called from my main page on doc.ready():

    <script>
    $(document).ready(function () {
        var masterKey = '@Model.MasterKey';

        //load degree overview
        LoadCurrentCourses(masterKey);

    });
</script>

我想做的是返回一个数据,我希望html慢慢淡入主页,替换gif和标头.现在,它可以正常工作,可以加载并替换所有内容,但是我似乎无法弄清楚应该在哪里放置jQuery .fadein()方法.

What I am trying to do is one the data gets returned I would like the html to slowly fade in to the main page, replacing the gif and header. Right now it works fine, everything loads, and is replaced, but I can't seem to figure out where I should put the jQuery .fadein() method.

有什么想法吗?

推荐答案

您应在淡入之前加载文本

You should load the text before fading in

success: function (evt) {
    $('#currentCourses').html(evt);
    $('#currentCourses').fadeIn(1500);
},

在淡入之前,您可能还需要淡出或隐藏该容器,否则它似乎什么也没做,只会加载新数据.

You may also need to fadeout or hide that container before fading in, or it will appear to do nothing and just load the new data.

这篇关于我在Ajax成功回调中将jQuery .fade()函数放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆