我有一个表单,我正在使用 j Query validate插件来验证表单。我想在验证部分完成后调用ajax代码提交表单。
我该怎么办:
// CALL THE postform code if the form validation is complete?
// THIS IS THE FORM VALIDATION CODE
$(document).ready(function() {
$("#myForm").validate({
rules: {
password: "required",
password_confirm: {
equalTo: "#password"
}
}
});
});
// THIS IS THE AJAX FORM SUBMISSION CODE
// I WANT THIS CODE EXECUTED IF CODE ABOVE IS OK
function postform()
{
dataString = $("#myForm").serialize();
$.ajax({
url: 'https:/www.someothersite.com'+dataString,
type: 'GET',
dataType: 'html',
timeout: 9000,
error: function(){
alert('Error posting to other site');
},
success: function(html){
window.location.href="http://www.mysite.com/?action=success";
}
});
return false;
}
最佳答案
它就在 documentation 中.
$("#myForm").validate({
submitHandler: function(form) {
postForm();
}
})
关于javascript - 验证完成后jquery调用表单ajax提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5225371/