繁体   English   中英

我在Ajax成功回调中将jQuery .fade()函数放在哪里?

[英]where do i put jQuery .fade() function in ajax success callback?

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

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。

<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:

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

        //load degree overview
        LoadCurrentCourses(masterKey);

    });
</script>

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

有任何想法吗?

您应在淡入之前加载文本

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

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

应该是这样的:

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

在元素填充淡入,否则在.fadeIn()回调内调用.html()会导致:

fade--(fade ends)-->--(HTML applied)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM