I am trying to query aax using getJSON, but it does not return the value. What am I doing wrong?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script>$(document).ready(function(){$("#ver").click(function() {
nome=$("#course").attr("value");
$.getJSON("teste3.php", {cpf_cnpj:nome}, function(json){
$("#cpf_cnpj").html(json[0].cpf_cnpj);
$("#rsocial").html(json[0].cnh);
});
});
});
</script>
</head>
<body>
<strong>Cliente:</strong>
<input type="text" name="cliente" id="course" value="00.000.000/0000-00" size="40" />
<input type="button" value="ver" id="ver" />
<p>
<input type="text" id="cpf_cnpj" name="cpf_cnpj" value="">
<input type="text" id="rsocial" name="rsocial" value="">
</body>
</html>
Test3.php file
<?php
$conexao = mysql_connect('localhost', '', '') or die ("Erro na conexão ao banco de dados.");
mysql_select_db('',$conexao) or die ("Erro ao selecionar a base de dados.");
$selec = "SELECT ID_Cliente, cpf_cnpj, rsocial FROM clientes WHERE cpf_cnpj = '".$_GET["cpf_cnpj"]."' ";
$exec = mysql_query($selec, $conexao) or die(mysql_error());
while($campos=mysql_fetch_array($exec)) {
extract($campos);
$Array = Array();
$Array[] = Array("ID_Cliente" => "$ID_Cliente", "cpf_cnpj" => "$cpf_cnpj", "rsocial" => "$rsocial");
$json_encode = json_encode($Array);
echo $json_encode;
}
?>