我創建一個jQuery驗證和jQuery的Ajax提交聯繫表格。隱藏阿賈克斯謝謝你的消息,在3秒鐘後,並顯示主窗體
通過Ajax被顯示3秒鐘的mesage應該是用戶可見,該形式應當重新出現之後的消息之後。
這裏是我的HTML codespec:
<form id="contactForm" name="contactForm" method="post" action="">
<input type="text" placeholder="Name" id="txtName" name="name" class="required" style="color:#999;" /><br />
<input type="text" name="email" id="txtEmail" placeholder="E-mail" class="required" style="color:#999;" /><br />
<textarea id="textareaMessage" name="message" rows="5" cols="10" class="required" style="color:#999;"></textarea><br /><br />
<input class="submit" type="submit" value="Submit"/>
</form>
這裏是我的jQuery驗證和jQuery的Ajax提交codespec:
<script>
$(document).ready(function(){
$("#contactForm").validate({
rules: {
name: "required",// simple rule, converted to {required:true}
email: {// compound rule
required: true,
email: true
},
message: {
required: true
}
},
submitHandler: function(form) {
$.ajax({
type: "POST",
url: "send.php",
data: $(form).serialize(),
timeout: 3000,
success: function() {
$('#divContactFrm').html("<div id='divSuccessMsg'></div>");
$('#divSuccessMsg').html("Thank you! Your message has been sent to us. We will be getting back to you within 24 hours.")
.hide()
.fadeIn(1500, function() { $('#divSuccessMsg'); });
},
error: function() {
$('#divContactFrm').html("<div id='divErrorMsg'></div>");
$('#divErrorMsg').html("Something is going wrong...")
.hide()
.fadeIn(1500, function() { $('#divErrorMsg'); });
}
});
return false;
}
});
});
</script>
任何幫助將不勝感激。
你能說出你正在面對的這個實現嗎?在jsfiddle.net現場演示可以幫助過 – 2013-04-26 12:52:55
我不是面臨的Ajax或jQuery驗證任何問題。我想知道如何使在3秒後阿賈克斯消息消失,使窗體重新出現......這裏是現場演示的鏈接... http://www.ivanbayross.com/jquerytest/ – mkb 2013-04-26 13:13:59