jQuery-验证插件提交表单时出错
我正在使用jQuery验证插件。。。并尝试使用ajax发布数据 我发现的问题是,一旦ajax运行,它就会在表单标记中提交默认的“action” 我的jQuery代码如下,我希望有人能帮助我jQuery-验证插件提交表单时出错,jquery,jquery-validate,Jquery,Jquery Validate,我正在使用jQuery验证插件。。。并尝试使用ajax发布数据 我发现的问题是,一旦ajax运行,它就会在表单标记中提交默认的“action” 我的jQuery代码如下,我希望有人能帮助我 <script type="text/javascript"> jQuery(document).ready(function() { var platinumForm = jQuery('#platinum-form');
<script type="text/javascript">
jQuery(document).ready(function() {
var platinumForm = jQuery('#platinum-form');
platinumForm.validate({
rules: {
fullname: "required",
email: {
required: true,
email: true
}
},
messages: {
fullname: "Please enter your Fullname",
email: "Please enter a valid Email Address"
},
errorPlacement: function(error, element) {
error.appendTo( element.prev() );
},
submitHandler: function() {
jQuery('#platinum-form').fadeOut();
var iName = platinumForm.find('#fullname');
var data = 'fullname=' + iName.val();
$.ajax({
url: "/my-processing-page.php",
type: "POST",
data: data,
dataType: "html",
cache: false,
success: function(html){
console.log(html);
if (html.indexOf('Sorry') > -1) {
$('#paymentMessage').html(html).fadeIn('slow');
} else {
$('#form-payment-content').slideUp('slow', function(){
$('#thankyouMessage .message').html(html).parent().fadeIn('slow');
});
}
}
});
},
})
});
</script>
jQuery(文档).ready(函数(){
var platinumForm=jQuery(“#白金形式”);
platinumForm.validate({
规则:{
全名:“必选”,
电邮:{
要求:正确,
电子邮件:真的
}
},
信息:{
全名:“请输入您的全名”,
电子邮件:“请输入有效的电子邮件地址”
},
errorPlacement:函数(错误,元素){
error.appendTo(element.prev());
},
submitHandler:function(){
jQuery(“#白金形式”).fadeOut();
var iName=platinumForm.find(“#全名”);
var data='fullname='+iName.val();
$.ajax({
url:“/my processing page.php”,
类型:“POST”,
数据:数据,
数据类型:“html”,
cache:false,
成功:函数(html){
log(html);
if(html.indexOf('Sorry')>-1){
$('#paymentMessage').html(html).fadeIn('slow');
}否则{
$(“#表单支付内容”).slideUp('slow',function(){
$('#thankyouMessage.message').html(html.parent().fadeIn('slow');
});
}
}
});
},
})
});
谢谢写
返回false代码>在$之后。ajax
.......
$.ajax({
url: "/my-processing-page.php",
type: "POST",
data: data,
dataType: "html",
cache: false,
success: function(html){
console.log(html);
if (html.indexOf('Sorry') > -1) {
$('#paymentMessage').html(html).fadeIn('slow');
} else {
$('#form-payment-content').slideUp('slow', function(){
$('#thankyouMessage .message').html(html).parent().fadeIn('slow');
});
}
}
});
return false;
......
尝试添加返回false代码>提交给您的提交处理程序。这似乎不起作用这不起作用。。。当我将$.ajax更改为jQuery.ajax时,它不会像我希望的那样提交表单,但是ajax不能正常工作