I am trying to print a table using php, ajax and mysql.
I have this stretch in Html
<!DOCTYPE html>
<html>
<head>
<title>Teste Ajax</title>
<?php
require("cabecalho.php");
?>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="ajax.js"></script>
</head>
<body>
<center>
<table border="1" width="500">
<thead>
<tr>
<th>Origem</th>
<th>Papel</th>
<th>Usuario</th>
</tr>
</thead>
<tbody id="listateste">
</tbody>
</table>
</center>
</body>
</html>
ajax.js
$(document).ready(function(){
$('#listateste').empty(); //Limpando a tabela
$.ajax({
type:'post', //Definimos o método HTTP usado
dataType: 'json', //Definimos o tipo de retorno
url: 'puxa.php',//Definindo o arquivo onde serão buscados os dados
success: function(dados){
for(var i=0;dados.length>i;i++){
//Adicionando registros retornados na tabela
$('#listateste').append('<tr><td>'+dados[i].origem+'</td><td>'+dados[i].Papel+'</td><td>'+dados[i].usuario+'</td></tr>');
}
}
});
});
And PHP
<?php
header('Content-type: application/json');
include ("Conectcma.php");
$qryLista = mysql_query("SELECT * FROM reg_qm_papel", $conexao);
$resultado = array();
$resultado[] = mysql_fetch_assoc($qryLista);
echo json_encode($resultado);
?>
If I return the array inside PHP itself, the array is printed but apparently the value does not arrive in Js, I took the mysql_fetch_assoc () from the loop just to test, but it made no difference Can anyone tell me what I'm doing wrong?