Return data from a PHP/JQUERY - Unexpected end of input

Asked

Viewed 61 times

1

I have a field called usuario_email, which in turn, the user type the desired email, triggers the jquery to search in the database if this email already exists there, if it exists, returns message if it does not return available email message.

But the only message coming on the console is:

Uncaught Syntaxerror: Unexpected end of input

The PHP file is returning correctly! The problem is even in this jquery.

<label for="inputType" class="col-md-2 control-label">E-mail de Acesso</label>
<label for="inputType" class="col-md-2 control-label">E-mail de Acesso</label>
<div class="col-md-4">
    <input type="text" class="form-control" id="usuario_email" name="usuario_email" placeholder="Digite seu E-mail" autocomplete="off">
    <div id='resposta'></div>
</div>

jQuery

    var email = $("#usuario_email");
        email.blur(function() {
            $.ajax({ 
                url: '/outras/verificaEmail.php', 
                type: 'POST', 
                data:{"email" : email.val()}, 
                success: function(data) { 
                console.log(data); 
                data = $.parseJSON(data); 
                $("#resposta").text(data.email);
            } 
        }); 
    }); 

Code from the checkEmail.php

<?php
#Verifica se tem um email para pesquisa
if(isset($_POST['usuario_email'])){ 

    #Recebe o Email Postado
    $emailPostado = $_POST['usuario_email'];

    #Conecta banco de dados 
    $con = mysqli_connect("localhost", "root", "", "outrasintencoes");
    $sql = mysqli_query($con, "SELECT * FROM usuarios WHERE email = '{$emailPostado}'") or print mysql_error();

    #Se o retorno for maior do que zero, diz que já existe um.
    if(mysqli_num_rows($sql)>0) 
        echo json_encode(array('email' => 'Ja existe um usuário cadastrado com este email.')); 
    else 
        echo json_encode(array('email' => 'Parabéns! Você poderá usar este e-mail como usuário.' )); 
}
?>
  • You can test console.log(typeof data); on the same line as your console.log? which?

  • Returns the same error.

  • But returns error before showing this line? which line is the error? can you locate the code on the error line?

  • Appeared: string, on top of error.

  • Okay, you can put that string here?

  • No, appeared only written string...

Show 1 more comment

1 answer

-1

correction: change your var email = $("#usuario_email");

for var email = $("#usuario_email").val();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.