[英]The jquery validating the form fields but not submitting the form data to targeted file
I am trying to validate the contact us form using jquery and ajax, the form fields are validating successfully ,but the data not submitted to php file ie contact_submit.php. 我正在尝试使用jquery和ajax验证联系我们表单,表单字段正在成功验证,但是数据未提交到php文件,即contact_submit.php。 please give me answer...... thank you !
请给我答案……谢谢!
$(document).ready(function(){
var $form = $(this);
$('#frm').validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
mobile: {
minlength: 10,
maxlength:10,
number:true,
required: true
},
message: {
required: true
}
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('text-success').addClass('has-warning');
},
/*success: function(element) {
element
.text('OK!').addClass('valid')
.closest('.control-group').removeClass('has-warning').addClass('text-success');
},*/
submitHandler: function(form)
{
$ajax({
url: "contact_submit.php",
type: "post",
data: $($form).serialize(),
success:function(response)
{
$('#msg').html('Your form is submited');
}
});
}
});
});
I think there is mistake in my submithandler. 我认为我的提交处理程序中有错误。
我认为问题出在在线data: $($form).serialize()
form
前面的美元符号不应存在。
First you are using var $form = $(this)
inside your document ready function and here $(this) refers to document not form and inside success handler function you using this $($form).serialize()
==> returns nothing. 首先,您在文档就绪函数中使用
var $form = $(this)
,这里$(this)指文档不是表单,在内部成功处理函数中,您使用此$($form).serialize()
==>不返回任何内容。
Changes : removed var $form = $(this)
line and added $("#frm").serialize();
更改:删除了
var $form = $(this)
行,并添加了$("#frm").serialize();
in submitHandler
. 在
submitHandler
。
Try this Code.. 试试这个代码..
$(document).ready(function(){
$('#frm').validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
mobile: {
minlength: 10,
maxlength:10,
number:true,
required: true
},
message: {
required: true
}
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('text-success').addClass('has-warning');
},
/*success: function(element) {
element
.text('OK!').addClass('valid')
.closest('.control-group').removeClass('has-warning').addClass('text-success');
},*/
submitHandler: function(form)
{
$ajax({
url: "contact_submit.php",
type: "post",
data: $("#frm").serialize(), //Or $(form).serialize()
success:function(response)
{
$('#msg').html('Your form is submited');
}
});
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.