I have the following function that validates me if the email entered in the database exists and works well for me
var emailExistente = false;
//validar email en el registro
$("#correo_usuario").change(function(){
var email = $("#correo_usuario").val();
var datos = new FormData();
datos.append("validarEmail", email);
$.ajax({
url:"views/modulos/ajax.php",
method:"POST",
data: datos,
cache: false,
contentType: false,
processData: false,
success:function(respuesta){
if(respuesta == 0){
$("label[for='correo_usuario'] span").html('<p class="text-danger">Este email ya existe en la base de datos</p>');
$("input[id='correo_usuario']").parent().addClass('has-danger');
emailExistente = false;
}
if(respuesta == 1){
$("label[for='correo_usuario']").parent().addClass('has-success');
$("label[for='correo_usuario'] span").html('');
$("input[id='correo_usuario']").parent().removeClass('has-danger');
$("input[id='correo_usuario']").parent().addClass('has-success');
emailExistente = true;
}
}
});
});
Now the problem is that although the mail exists and I put a false like this is executing the submit, I would appreciate if you could help me create a function or something that prevents me from sending the submit if the email exists