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?– Sergio
Returns the same error.
– Sr. André Baill
But returns error before showing this line? which line is the error? can you locate the code on the error line?
– Sergio
Appeared: string, on top of error.
– Sr. André Baill
Okay, you can put that string here?
– Sergio
No, appeared only written string...
– Sr. André Baill