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

我有一个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("

Error occured retrieving current courses

"); } });

}

#currentCourses标记只有一个标题并在那里加载.gif文件。

 

Current Courses

从doc.ready()的主页面调用ajax:

   $(document).ready(function () { var masterKey = '@Model.MasterKey'; //load degree overview LoadCurrentCourses(masterKey); });  

我想要做的是返回数据我希望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)