我正在使用来自: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 的 JQuery 验证器
我已经编写了我需要的 JQuery,它可以正确验证,但是我的提交功能的最后一部分无法正常工作。
$("#commentForm").validate({
rules: {
email_options_name: {
required: true
},
email_options_company: {
required: true
},
email_options_country: {
required: true
},
email_option_email: {
required: true,
email: true
},
check_options: {
required: true,
minlength: 1
}
},
});
$("#commentForm").submit(function(){
var valid = $("#commentForm").valid();
if (valid) {
$.post('scripts/process_email_initial_form.php',$(this).serialize(), function(o) {
location.reload();
}, 'json');
} else {
$('.full-error').show();
}
return false;
});
$.extend($.validator.messages, {
required: "!",
email: "!"
});
}
当提交有效时,脚本 process_email_initial_form.php
被调用并正确处理(通过查看 firebug),如果不是,则 div 会显示。问题是,当脚本运行完毕后,location.reload();
不会调用。理想情况下,我想定向到成功页面,但这也不起作用。
我尝试将 php header 函数放在 process_email_initial_form.php
的末尾,但这也不起作用。
非常感谢任何帮助。
最佳答案
根据 docs ,submitHandler 回调是“在验证后通过 Ajax 提交表单的正确位置。”
$("#commentForm").validate({
rules: {
// your rules here
},
submitHandler: function(form) {
// example below uses the 'form' plugin
// http://www.malsup.com/jquery/form/#api
$(form).ajaxSubmit({
success: function(){
window.location.href="newPage.php"
}
});
}
});
关于php - JQuery 验证器 - 有效提交时未调用成功函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667102/