json - problemas com dataType e success: function(retorno)
Ao executar o codigo tem dado alguns problemas.
Primeiro: o DataType gera erro logo de início. Se eu troco por html, funciona melhor, todavia existe um outro erro:
function(retorno), esta funcao retorna valores nulos..
Abaixo o codigo php:
>
Citar
<?php
include("../conexao/conexao.php");
//header("Content-Type:" . "text/plain");
header("Content-Type: application/json");
$sql = "select titulo, texto, autoria from mysql";
echo $sql;
$exec = $conn->query($sql);
$rows = $exec->fetchAll( PDO::FETCH_ASSOC );
$dados = $rows;
die(json_encode($dados, JSON_PRETTY_PRINT));
?>
o script:
>
Citar
function carregarItens(){
var itens = "", url = "busca.php";
$.ajax({
url: url,
//cache: false,
dataType: "json",
beforeSend: function(){
$("h2").html("carregando...");
},
error: function(){
$("h2").html("erro");
},
success: function(retorno){
if (retorno[0].erro){
$("h2").html(retorno[0].erro);
}else{
// aqui obviamente vai dar problema, pois se a funcao retorno está retornando nulos, entao nada ira funcionar aqui.
for(var i = 0; i<=retorno.lenght; i++){
itens = "<tr>";
//itens = "<td>" + retorno*.data + "</td>";*
*
itens = "<td>" + retorno**.titulo + "</td>";*
*
itens = "<td>" + retorno**.texto + "</td>";*
*
itens = "<td>" + retorno**.autoria + "</td>";*
*
itens = itens + "</tr>";*
*
alert(itens);*
*
*
*
}*
*
$("#tabela tbody").html(itens);
*
*
**
*
*
}*
*
}*
*
});*
*
*
*
**
}
*
*
**
*
*
**
*
*
**
*
*
*
*
*
*
**
*
Discussão (5)
Carregando comentários...