我试图检查电子邮件值是否存在,因此在验证工作后我使用ajax检查电子邮件值。如果电子邮件存在,则应该有警报并且无法提交表单。但即使我的表中存在电子邮件值,表单仍会提交。这是脚本
$('#myForm').validate({
rules: {
email: {
required: true,
email: true
},
submitHandler : function(){
var email = $("#email").val();
$.ajax({
url:"<?=base_url('akun/emailcheck');?>",
type:"POST",
dataType:"JSON",
data:"email"+email,
success: function(responeData){
if(data==0){
alert('true');
}
else{
alert('false');
}
},
error: function(data){
alert('error');
}
});
}
}
答案 0 :(得分:1)
submitHandler
不是规则,它是自己的选项
$('#myForm').validate({
rules: {
email: {
required: true,
email: true
}
},
submitHandler: function(form) {
var email = $("#email").val();
$.ajax({
url: "<?=base_url('akun/emailcheck');?>",
type: "POST",
dataType: "JSON",
data: {email : email},
success: function(responseData) {
if (responseData == 0) { // note that you're expecting JSON, not an integer ?
alert('true');
// form.submit(); <-- WILL SUBMIT FORM
} else {
alert('false');
}
},
error: function(data) {
alert('error');
}
});
}
});