Consulta getJSON
Estou tentando fazer uma consulta aJax usando getJSON, mas não retorna o valor. O que estou fazendo de errado?
arquivo teste2.php
<!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').val();
$.getJSON("teste3.php", {cpf_cnpj:nome}, function(json){
$("#ID_Cliente").html(json[0].ID_Cliente);
$("#cpf_cnpj").html(json[0].cpf_cnpj);
$("#rsocial").html(json[0].rsocial);
});
});
});
</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="">
<input type="text" id="ID_Cliente" name="ID_Cliente" value="">
</body>
</html>
arquivo teste3.php
<?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("ID_Cliente" => "$ID_Cliente", "cpf_cnpj" => "$cpf_cnpj", "rsocial" => "$rsocial");
$json_encode = json_encode($Array);
echo $json_encode;
echo $json_encode->{'rsocial'};
}
?>
Imagem do console
/applications/core/interface/imageproxy/imageproxy.php?img=http://i.imgur.com/kfULbPi.png&key=de6cd9490741b7aa741550a70ca15f814a6293e94f2b42c63462be13d487e9fb" alt="kfULbPi.png" />
Acessando o arquivo /teste3.php?cpf_cnpj=00.000.000/0000-00 pelo navegador aparece o resultado normalmente.
>
{"ID_Cliente":"1","cpf_cnpj":"00.000.000\/0000-00","rsocial":"Teste ME"}
Discussão (1)
Carregando comentários...