gpt4 book ai didi

javascript - 验证完成后jquery调用表单ajax提交

转载 作者:行者123 更新时间:2023-11-28 14:00:53 25 4
gpt4 key购买 nike

我有一个表单,我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com