JQuery AJAX 成功 +淡入
我使用 AJAX 将调查内容加载到页面上的容器中,在转换过程中,我淡出容器并在完成后淡入。它在第 1-4 页上工作正常,但在第 5 页上停止工作。第 5 页的内容已加载,但容器不会淡入。
success: function(data){
$("div#surveyContainer").fadeOut(function(){
$("div#surveyContainer").html(data).hide().fadeIn();
}); // end fadeout
}
第 5 页中的任何地方都没有提及 surveyContainer
。我所能想到的是,某些内容超时导致 fadeIn
未触发。加载时间约为36ms。我将 php 脚本设置为发送 data
的位置以报告所有错误(并且数据很好地进入数据库),但我得到的只是我期望的内容,但容器保持display:none
。如果我删除淡入淡出,一切都会正常:/
我也尝试过此操作,但无济于事:
success: function(data){
$("div#surveyContainer").fadeOut(function(){
$("div#surveyContainer").html(data);
$("div#surveyContainer").fadeIn();
}); // end fadeout
}
I'm using AJAX to load survey content into a container on a page, and during the transition, I fadeOut the container and fadeIn when it's done. It works fine for pages 1-4, but stops working for page 5. The content loads for page 5, but the container doesn't fadeIn.
success: function(data){
$("div#surveyContainer").fadeOut(function(){
$("div#surveyContainer").html(data).hide().fadeIn();
}); // end fadeout
}
There is no reference to surveyContainer
anywhere in page 5. All I can think of is that something is timing out causing the fadeIn
to not get triggered. The load time is about 36ms. I set the php script to where it's sending data
to report all errors (and the data is making it into the Db just fine), but all I'm getting is the content I expect, but the container stays display:none
. If I remove the fades, everything works fine :/
I've also tried this to no avail:
success: function(data){
$("div#surveyContainer").fadeOut(function(){
$("div#surveyContainer").html(data);
$("div#surveyContainer").fadeIn();
}); // end fadeout
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加
.stop();
请参阅此处的参考这应该停止当前正在发生的任何动画,强制它们直接到达终点(它们要进行动画处理的位置)并清除动画队列。您也可以通过这种方式摆脱
hide()
。另外,您可以在回调中使用
this
,好吧,我不知道为什么。但你可以。Try adding a
.stop();
see reference hereThis should stop any animations that are currently happening, force them to go straight to their ending point (where they were animating to) and clear the animation queue. You can probably get rid of the
hide()
this way too.Also, you can just use
this
inside the callback for, well, I dont' know why. but you can.不知道为什么它会在单个页面上中断。
也许你可以在
.hide()
的回调中尝试一下:正如Interstellar_Coder指出的。当你将其淡出。您现在只需加载数据并将其淡入即可。
Not sure why it would break on a individual page tho.
Perhaps you could try it in the callback of
.hide()
:As Interstellar_Coder pointed out. You have already hidden the
div#surveyContainer
when you faded it out. You now just need to load up your data and fade it in.不要链接到 http://code.jquery.com/jquery-latest.js 来自使用加密 (HTTPS) 的页面。在本地托管代码。
Don't link to http://code.jquery.com/jquery-latest.js from a page using encryption (HTTPS). Host the code locally.