I am doing a query in mySQL using $.getJSON
, but I am not able to return 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);
}
Debug Image: