在ajax提交的成功函数中添加setTimeout
我能做对大部分事情。成功后,覆盖层 div 会随着来自服务器的消息淡入。显然是“.fadeOut(5000);”只是在 5 秒内淡出,我需要它做的只是保持可见 5 秒然后淡出,但我不熟悉如何在这里集成 setTimeout 函数,我感谢任何帮助!
submitHandler: function(form) {
var txt = $("textarea#foo").val();
var cont = $("#submitErrorOverlay p");
txt = encodeURIComponent(txt);
$.ajax({
type: 'POST',
url: form.action,
data: {foo:txt , action: 'foofunction'},
success: function(result) {
$('#submitErrorOverlay').fadeIn(500).html('<p>' + 'Congratulations' + result.msg + '<p>')****.fadeOut(5000);****
$('textarea').val('');
},
error: function (data) {
$('#msg').fadeIn(500).html('Awww Snaaap!' + data);
$('textarea').val('');
},
dataType:'json'
});
编辑抱歉,我忘记了 .delay - 请忽略。
I'm able to get most of this right. On success an overlay div fades in with messages from the server. Obviously ".fadeOut(5000);" just fades it out over 5 seconds, what I need it to do is only stay visible for 5 seconds then fade out, but am not familiar with how to integrate a setTimeout function here, I appreciate any help!
submitHandler: function(form) {
var txt = $("textarea#foo").val();
var cont = $("#submitErrorOverlay p");
txt = encodeURIComponent(txt);
$.ajax({
type: 'POST',
url: form.action,
data: {foo:txt , action: 'foofunction'},
success: function(result) {
$('#submitErrorOverlay').fadeIn(500).html('<p>' + 'Congratulations' + result.msg + '<p>')****.fadeOut(5000);****
$('textarea').val('');
},
error: function (data) {
$('#msg').fadeIn(500).html('Awww Snaaap!' + data);
$('textarea').val('');
},
dataType:'json'
});
EDIT apologies, I forgot about .delay - please disregard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么
delay()
呢? http://api.jquery.com/delay/What about
delay()
? http://api.jquery.com/delay/