Php JQuery验证器-未在有效提交时调用成功函数
我从以下位置使用JQuery验证程序: 我已经编写了我需要的JQuery,它可以正确地进行验证,但是提交函数的最后一部分工作不正常Php JQuery验证器-未在有效提交时调用成功函数,php,javascript,jquery,validation,jquery-validate,Php,Javascript,Jquery,Validation,Jquery Validate,我从以下位置使用JQuery验证程序: 我已经编写了我需要的JQuery,它可以正确地进行验证,但是提交函数的最后一部分工作不正常 $("#commentForm").validate({ rules: { email_options_name: { required: true }, email_options_company: { required: true },
$("#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\u email\u initial\u form.php
,并正确处理(查看firebug),如果没有,则显示div。问题是,当脚本完成运行location.reload()时代码>不调用。理想情况下,我想直接进入一个成功页面,但这也不起作用
我试图在process\u email\u initial\u form.php
的末尾添加一个php头函数,但这也不起作用
非常感谢您的帮助。您只检查了表格是否有效。选中此项将仅返回布尔值,它不会设置错误消息。在显示之前,您需要将错误分配到$('.full error')
试一试
您只检查了表单是否有效。选中此项将仅返回布尔值,它不会设置错误消息。在显示之前,您需要将错误分配到$('.full error')
试一试
您是否尝试使用done
事件
$.post(
'scripts/process_email_initial_form.php',
$(this).serialize(),
function(o) {
console.log('success');
},
'json'
).done(function(o){
window.location.replace("success.php");
});
ajax页面中的PHP标题不会将当前页面重定向到成功页面。它只会使ajax页面重定向到定义的标题
您可以尝试使用jquery提交表单,而不是使用window.location.replace
$("#commentForm").submit(function(){
var valid = $("#commentForm").valid();
if (valid) {
$.post(
'scripts/process_email_initial_form.php',
$(this).serialize(),
function(o) {
console.log('success');
},
'json')
.done(function(o) {
$(this).attr('action', 'success.php');
return true;
});
} else {
$('.full-error').show();
return false;
}
});
或
您是否尝试使用done
事件
$.post(
'scripts/process_email_initial_form.php',
$(this).serialize(),
function(o) {
console.log('success');
},
'json'
).done(function(o){
window.location.replace("success.php");
});
ajax页面中的PHP标题不会将当前页面重定向到成功页面。它只会使ajax页面重定向到定义的标题
您可以尝试使用jquery提交表单,而不是使用window.location.replace
$("#commentForm").submit(function(){
var valid = $("#commentForm").valid();
if (valid) {
$.post(
'scripts/process_email_initial_form.php',
$(this).serialize(),
function(o) {
console.log('success');
},
'json')
.done(function(o) {
$(this).attr('action', 'success.php');
return true;
});
} else {
$('.full-error').show();
return false;
}
});
或
根据,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"
}
});
}
});
根据,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"
}
});
}
});
. 使用submitHandler
回调函数。它是您放置ajax
的地方。您的外部submit
处理程序正在破坏插件的内置提交处理程序。。使用submitHandler
回调函数。它是您放置ajax
的地方。您的外部submit
处理程序正在破坏插件的内置提交处理程序。