[英]how to redirect after form submission with jQuery validate
我正在使用jQuery validate插件在提交聯系表單之前對其進行驗證。
問題是成功提交表單后,我應該重定向到“謝謝”頁面。
這可能嗎?
我的驗證代碼如下所示:
$("#contactForm").validate({
//debug: true,
rules: {
fullname: "required",
email: {
required: true,
email: true
}
},
submitHandler: function(form) {
form.submit();
window.location.href = "/confirm.html";
}
});
由於某些原因
window.location.href =“ /confirm.html”);
永遠不會執行。
謝謝你的幫助,
安東尼
經過一番嘗試和錯誤之后,在將表單提交到簡單表單后,我設法重定向到“謝謝”頁面。 這必須通過ajax調用來完成:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"></script>
<script>
$("#contactForm").validate({
rules: {
fullname: "required",
email: {
required: true,
email: true
}
},
submitHandler: function(form) {
$.ajax({
dataType: 'jsonp',
url: "http://getsimpleform.com/messages/ajax?form_api_token=my-secret-token",
data: $("#contactForm").serialize()
}).done(function() {
//callback which can be used to show a thank you message
//and reset the form
window.location.href = "/confirm.html";
});
}
});
</script>
不,我能夠驗證聯系表單並將其提交給簡單表單服務,然后重定向到“謝謝”頁面,所有這些都無需任何服務器端代碼:smile:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.