0
When getJSON, does it not find what is returned? I’m leaving as Fazio, but not the right one.
$("#email").focusout(function() {
emailDigitado = $("#email").val();
$.getJSON("inc_verificaCadastro.php", {email:emailDigitado}, function(json){
if (json[0].email == ''){
$('#divSenha').attr('class', 'mostrar');
$("#senha").attr("required", true);
}else{
$("#id_cadastro").val(json[0].id_cadastro);
}
});
});
inc_verificationCadastro.php file
<?php
header('Content-Type: application/json; charset=utf-8');
include 'config.php';
$rs = $conexao->query("SELECT ID_Cadastro, email FROM cadastro WHERE email = '".$_GET['email']."' ");
$Array = Array();
while($row = $rs->fetch_assoc()) {
$Array[] = Array(
"email" => $row['email'],
"id_cadastro" => $row['ID_Cadastro']
);
}
$json_encode = json_encode($Array);
echo $json_encode;
?>
@bfavaretto I edited the initial post. Still not entering the initial IF.
– Tiago
@bfavaretto Ahhhh... see if I’m right. When the search is not done successfully
json[0].email
returns Fazio. So you have no way to compare anything with empty.– Tiago
Test whether
json.length > 0
before tampering with the server response– bfavaretto
@bfavaretto It worked, I put
json.length != 1
– Tiago
???
!= 1
it will enter if you have 0 or 2+, and Else if you have exactly 1.– bfavaretto
@bfavaretto Here it worked so....
– Tiago