Print table with ajax and php

3

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?

By dev tools tb does not return anything

    
asked by anonymous 30.11.2017 / 17:37

1 answer

2

In my case, I have a version where the error that the mysql function is deprecated, only add this line at the beginning of your file pulls.php:

ini_set('display_errors', 0);

Although not advisable. My response in devtools, yours has to be something like this, check:

    
30.11.2017 / 18:23