hy! I have a signup form. I want to submit form using ajax after complete validation.I used jquery plugin for validation. But as soon as, i simply click on any field, the ajax request automatically sent to server and return a response before hitting submit button. Also, I am getting the "missing value" message. I do not know, where is the mistake. Help me !
hy !我有一个注册表。我想在完成验证后使用ajax提交表单。我使用jquery插件进行验证。但是,只要单击任何字段,ajax请求就会自动发送到服务器,并在单击submit按钮之前返回响应。此外,我还得到了“丢失的值”消息。我不知道,哪里出错了。帮帮我!
Validation.js
Validation.js
$(document).ready(function() {
$('#signup_form').formValidation({
// To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
}
})
.on('success.form.bv', function(e) {
$('#signup_form').data('formValidation').resetForm();
});
});
form_signup.php
form_signup.php
<script type="text/javascript">
$(document).ready(function (){
$('#signup_form').submit(function(e){ e.preventDefault(); });
$(function(){
$("#signup_form").click(function(event){
//event.preventDefault();
$.ajax({
url:'form_process.php',
type:'POST',
data:$(this).serialize(),
success:function(result){
alert(result);
}
});
});
});
});
form_process.php
form_process.php
<?php
print_r($_POST);
require_once './functions/functions.php';
if(isset($_POST['FirstName']))
{
echo $firstName = $_POST['FirstName'];
}
else{ echo ("missing value!");}
1 个解决方案
#1
3
your were calling ajax on form click inside form submit ?? , you need to call it on form submit instead !
您调用的是表单中的ajax单击表单提交?,你需要在表单上调用它!
$(document).ready(function(){
$('#signup_form').submit(function(e){
e.preventDefault();
$.ajax({
url:'form_process.php',
type:'POST',
data: $('#signup_form').serialize(),
success:function(result){
alert(result);
}
});
});
});
try this way...
试试这个方法…
Hope it helps
希望它能帮助
#1
3
your were calling ajax on form click inside form submit ?? , you need to call it on form submit instead !
您调用的是表单中的ajax单击表单提交?,你需要在表单上调用它!
$(document).ready(function(){
$('#signup_form').submit(function(e){
e.preventDefault();
$.ajax({
url:'form_process.php',
type:'POST',
data: $('#signup_form').serialize(),
success:function(result){
alert(result);
}
});
});
});
try this way...
试试这个方法…
Hope it helps
希望它能帮助