Intel XDK $.getJSON does not return php value

Asked

Viewed 99 times

0

I’m making a query in mysql using the $.getJSON, but I’m not getting back the value.

test page:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function() {  


    $("#btnCriarConta").click(function() {
        var nomeCondominio = $("#inputNomeCondominio").val();
        var operacao = "addCondominio";
        $.getJSON("http://url.com.br/appOperacoes.php", {operacao:operacao,nome:nomeCondominio}, function(json){
            $("#retorno1").val(json[0].message);
            $("#retorno2").html(json[0].message);

        });
    });

});
</script>
</head>

<body>
<h1>Valores</h1>
<input type="text" id="retorno1">

<p id="retorno2"></p>



<input type="text" id="inputNomeCondominio" placeholder="Nome" value="Vila Aribiri">

 <input type="button" id="btnCriarConta" value="OK">
</body>
</html>

appOperacoes.php page

if($_GET['operacao'] == 'addCondominio'){

    $nome = subdominio($_GET['nome']);

    $rs = $mysqli->query("SELECT subdominio FROM condominios WHERE subdominio = '".$nome."' ");
    $row = $rs->fetch_assoc();
    $registros = mysqli_num_rows($rs);

    if ($registros == 0){
        $retorno = array('message'=>'sem registro');
    }else{
        $retorno = array('message'=>'Possui registro');
    }

    echo  json_encode($retorno, true);

}

Image of the debug:

inserir a descrição da imagem aqui

1 answer

1

RESIDUE!

For those who have the same doubt, just missing [] in the $return, being like this:

$retorno[] = array();

Browser other questions tagged

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