我有一个 jquery 脚本,它使用 bootstrapvalidator ( http://bootstrapvalidator.com/ )验证我的表单,然后如果验证成功(复选框选中,不为空等)它会进行 ajax 调用。
问题是当我尝试使用 ICheck 插件(http://fronteed.com/iCheck/)实现它时
不是对页面“proceed.php”进行ajax请求,而是将我重定向到它(这是一个带有json调用的php页面)。
所以基本上当我尝试使用 Icheck 插件实现我的 ajax 调用时,它会重定向而不是执行 ajax(有点失去 ajax 的目的!)
我是 jQuery 的新手,我很确定这是一个简单的语法错误,因此我们将不胜感激。
该网站可以在这里测试:http: //entendu.x10.mx
$(document).ready(function() {
$("form")
.bootstrapValidator({
message: 'Pas valide',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitButtons: 'button[type="submit"]',
fields: {
nom: {
message: 'Votre nom est invalide',
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
stringLength: {
min: 1,
max: 60,
message: 'Le champ doit être compris entre 6 et 60 caractères'
},
regexp: {
regexp: /^[a-zA-Z]*$/,
message: 'Le champ ne doit comporter que des lettres'
}
}
},
prenom: {
message: 'Votre prénom est invalide',
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
stringLength: {
min: 1,
max: 60,
message: 'Le champ doit être compris entre 6 et 60 caractères'
},
regexp: {
regexp: /^[a-zA-Z]*$/,
message: 'Le champ ne doit comporter que des lettres'
}
}
},
matricule: {
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
integer: {
message: 'Votre matricule doit être composé de chiffres uniquement'
} }
},
"date-dispo-from":{
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
date: {
message: 'La date doit être valide',
format: 'YYYY-MM-DD',
separator: '-'
}
}
},
"date-dispo-to":{
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
date: {
message: 'La date doit être valide',
format: 'YYYY-MM-DD',
separator: '-'
}
}
},
"dispo-travail-jours": {
validators: {
notEmpty: {
message: 'Le champ est obligatoire'
},
integer: {
message: 'Le nombre doit être situé entre 0 et 20 jours'
}
}
},
"check_date[]": {
validators: {
choice: {
min: 8,
message: 'Veuillez sélectionner au minimum 8 jours. (1 fin de semaine SUR 2 et 1 jour par semaine)'
}
}
}
}
})
.find('input[type="checkbox"]')
// Init iCheck elements
.iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
})
// Called when the radios/checkboxes are changed
.on('ifChanged', function(e) {
// Get the field name
var field = $(this).attr('name');
$('form').bootstrapValidator('revalidateField', field);
})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
var postData = $('form').serialize();
$.ajax(
{
url : 'process.php',
type: "POST",
data : postData,
dataType: 'json',
success:function(data, textStatus, jqXHR)
{
alert(postData);
$("#result").show('slow');
},
error: function(jqXHR, textStatus, errorThrown)
{
//if fails
}
});
});
});