I'm doing a simple query via getJSON, but it's not returning the values to be shown.
File testJson.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script><script>$(document).ready(function(){//$("#email").click(function() {
nome = "listar";
$.getJSON("testeConexaoMobileJson.php", {acao:nome}, function(json){
$("#nome").val(json[0].nome);
$("#email").val(json[0].email);
});
//});
});
</script>
</head>
<body>
<h1>Cardápio de Pizzas</h1>
<div id="email"></div>
<input type="text" name="nome" id="nome">
</body>
</html>
File testConexaoMobileJson.php
<?php
$mysqli = new mysqli('localhost','','',''); if($mysqli->connect_error){echo "Erro";exit();}
if($_GET['acao'] == 'listar'){
header('Content-Type: application/json; charset=utf-8');
$rs = $mysqli->query("SELECT * FROM cadastro");
$row_rs = $rs->fetch_assoc();
$row = $rs->fetch_array();
$registros = mysqli_num_rows($rs);
while($campos=mysqli_fetch_array($rs)) {
extract($campos);
$Array = Array();
$Array[] = Array(
"nome" => "$nome",
"email" => "$email",
);
$json_encode = json_encode($Array);
echo $json_encode;
}
}
?>
Result of testConexaoMobileJson.php file
Result:
[