提交后,刷新表单页面上的感谢信息
Refreshing the thankyou message on the form page after submitting
我在页面中有一个简单的表单。表单提交到同一页面,并在那里显示感谢信息。但问题是,我想删除感谢消息后几秒钟或刷新页面。有解决办法吗?
脚本如下:
<script>
/* ==============================================
Ajax Submiting For Email Subscriber Form.
=====================================================================*/
$("#subscriber_form").submit(function(e) {
$('#show_subscriber_msg').html('<div class=gen>Submiting..</div>');
var subscriberemail = $('#subscriberemail').val();
var formURL = $(this).attr("action");
var data = {
subscriberemail: subscriberemail
}
$.ajax({
url: formURL,
type: "POST",
data: data,
success: function(res) {
if (res == '1') {
$('#show_subscriber_msg').html('<div class=gen>Thanks for your interest in Water Lily Pond. We are going to get in touch with you very soon. </div>');
}
if (res == '5') {
$('#show_subscriber_msg').html('<div class=err>Please enter a valid email address</div>');
}
}
});
e.preventDefault();
//STOP default action
});
</script>
在你的成功回调中,为执行你期望行为的函数设置一个超时时间。
success: function(res) {
if (res == '1') {
$('#show_subscriber_msg').html('<div class=gen>Thanks for your interest in Water Lily Pond. We are going to get in touch with you very soon. </div>');
setTimeout(yourFunction, 5000);
}
if (res == '5') {
$('#show_subscriber_msg').html('<div class=err>Please enter a valid email address</div>');
}
}
function yourFunction() {
// your code here
}
success: function(res) {
if (res == '1') {
$('#show_subscriber_msg').html('<div class=gen>Thanks for your interest in Water Lily Pond. We are going to get in touch with you very soon. </div>');
setTimeout(function() {
$('#show_subscriber_msg').html('');
}, 5000);
}
if (res == '5') {
$('#show_subscriber_msg').html('<div class=err>Please enter a valid email address</div>');
}
}
在success
函数中,我将添加一个setTimeout
,如下所示:
success: function(res) {
if (res == '1') {
$('#show_subscriber_msg').html('<div class=gen>Thanks for your interest in Water Lily Pond. We are going to get in touch with you very soon. </div>');
setTimeout(function() {
// do what you want, for example:
$('#show_subscriber_msg').html('');
// this number is in milliseconds
}, 500);
}
}
数字,500
是等待执行代码
您可以使用setTimeout在几秒钟后删除$('#show_subscriber_msg')
的内容
success: function(res) {
if (res == '1') {
$('#show_subscriber_msg').html('<div class=gen>Thanks for your interest in Water Lily Pond. We are going to get in touch with you very soon. </div>');
}
if (res == '5') {
$('#show_subscriber_msg').html('<div class=err>Please enter a valid email address</div>');
}
setTimeout(function(){
$('#show_subscriber_msg').empty()
},5000)
}
empty
是一个jquery方法,用于删除所有子节点
试试下面这个:
success: function(response) {
if (response) {
$('#div_id').hide().html('Write Your message here').fadeIn('slow').delay(6000).hide(1);
}
}
你也可以使用jQuery延迟如果你想隐藏它或setTimout
$("#show_subscriber_msg").html('your html').delay(1000).fadeOut();
setTimeout(function() {
// your code to modify or hide the message div
}, 1000)
相关文章:
- json.success重定向到感谢页面
- 如何在没有物理感谢页面的情况下执行谷歌Adwords转化跟踪
- 如何将选择加入表单重定向到感谢页面
- ios设备,“必填”字段和感谢消息
- 如何使用Javascript重定向到默认值/感谢
- 表单提交后显示感谢信息mvc umbraco
- 如何在感谢页面上获得Shopify交易
- 在 SP 后添加感谢消息.用户界面.ModalDialog.showModalDialog() 已经上传了 flie
- 将用户重定向到感谢页面
- 在注册页面和感谢页面之间包含一个加载页面
- 通用谷歌分析跟踪发送/感谢页面
- 如何建立一个没有单独感谢页面的联系形式的谷歌分析目标跟踪
- 为什么没有出现感谢页面?
- 将表单内容更改为感谢信息
- jQuery -将联系人表单替换为'感谢消息'
- 在同一页上分别提交两份表格,并附上感谢信
- 表格提交后没有显示感谢信息
- 理解防反跳.感谢和任务返回
- 转到感谢.Aspx页后的调查
- 提交后,刷新表单页面上的感谢信息