Return getJSON

0

When getJSON, does not find it what is returned? I'm leaving like it does, but it's not right.

$("#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);
                }
            });
        });

file inc_verifyCadastro.php

<?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;
?>
    
asked by anonymous 31.07.2017 / 00:20

1 answer

0

To check if json is blank, try the following

if (!$.trim(json)){   
    alert("a variavel json esta em branco " + json);
}
else{   
    alert("a variavel json não esta em branco: " + json);
}
    
31.07.2017 / 20:14