Ajax query does not work [closed]

2

Well, a simple query ajax, php and mysql. This same code changed only by the field name works normally on another page.

$(document).ready(function(){
$('#email').keyup(function(){ 
var Email = $(this).val(); 
var EmailResult = $('#div_mensagem_valida_email'); 
if(Email.length > 3) { 
EmailResult.html('Verificando..'); 
var UrlToPass = 'action=email='+Email;
$.ajax({
type : 'POST',
data : UrlToPass,
url  : 'include/cadastra_novo_cliente_verifica.php',
success: function(responseText){ 
if(responseText == 1){
EmailResult.html('<span class="error">Ops, este e-mail já está cadastrado</span>');
}
else(responseText == 0){
EmailResult.html('');
}               
}
});
}else{
EmailResult.html('Aguardando...');
}
if(Email.length == 0) {
EmailResult.html('');
}
});

$('#email').keydown(function(e) { 
if (e.which == 32) {
return false;
}
});
});

The input is:

<input id="email" class="form-control input-lg" type="text" name="email" autocomplete="off" placeholder="Seu e-mail" required>

It just does not happen, in Firebug it does not return error

    
asked by anonymous 14.08.2015 / 23:22

1 answer

1

Here you forgot to elseif , see:

}
else(responseText == 0){

The correct one is:

}
else if(responseText == 0){

I recommend making a good indentation of the code too, should be something like:

$(document).ready(function() {
    $('#email').keyup(function() {
        var Email = $(this).val();
        var EmailResult = $('#div_mensagem_valida_email');
        if (Email.length > 3) {
            EmailResult.html('Verificando..');
            var UrlToPass = 'action=email=' + Email;
            $.ajax({
                type: 'POST',
                data: UrlToPass,
                url: 'include/cadastra_novo_cliente_verifica.php',
                success: function(responseText) {
                    if (responseText == 1) {
                        EmailResult.html('<span class="error">Ops, este e-mail já está cadastrado</span>');
                    } else if(responseText == 0) {
                        EmailResult.html('');
                    }
                }
            });
        } else {
            EmailResult.html('Aguardando...');
        }
        if (Email.length == 0) {
            EmailResult.html('');
        }
    });

    $('#email').keydown(function(e) {
        if (e.which == 32) {
            return false;
        }
    });
});

Tools like SublimeText or online tools like link should help you.

    
15.08.2015 / 02:11