file query.php
<?php
//header("Content-Type: application/json; charset-utf8");
header('Content-Type:' . "text/plain");
$baseDado = "teste";
$host = "localhost";
$user = "rafael";
$password = "159";
$ligacao = new PDO("mysql:dbname=$baseDado;host=$host", $user, $password);
$motor = $ligacao->prepare("SELECT * FROM user");
$motor->execute();
if($motor->rowCount()==0){
echo '<p>Sem Informações no banco de dado user</p>';
}
else
{
foreach ($motor as $value) {
//$delete = $value['id_user'];
echo json_encode($value);
//echo '#ID '.$value['id_user'].'<br>';
//echo 'Nome '.$value['nome'].'<br>';
//echo 'Email '.$value['email'].'<br>';
//echo 'Senha '.$value['pwd'].'<br>';
// echo '<div>';
// echo '<a href="delete.php?delete='.$delete.'">delete</a>';
// echo '</div>';
// echo '<hr>';
}
}
$ligacao = null;
?>
I have json data information that was generated from php with the method, json_encode (),
{"id_user":"1","0":"1","email":"[email protected]","1":"[email protected]","nome":"rafael","2":"rafael","pwd":"rafael","3":"rafael"}{"id_user":"2","0":"2","email":"[email protected]","1":"[email protected]","nome":"angela","2":"angela","pwd":"123","3":"123"}{"id_user":"3","0":"3","email":"[email protected]","1":"[email protected]","nome":"ricardo","2":"ricardo","pwd":"000","3":"000"}{"id_user":"4","0":"4","email":"[email protected]","1":"[email protected]","nome":"joao","2":"joao","pwd":"159","3":"159"}{"id_user":"5","0":"5","email":"[email protected]","1":"[email protected]","nome":"bruna","2":"bruna","pwd":"bruna","3":"bruna"}{"id_user":"6","0":"6","email":"[email protected]","1":"[email protected]","nome":"samsung","2":"samsung","pwd":"159357","3":"159357"}
When I request the data in the undefined presentation on the user page code below script
function bustarItem(){
var items = "";
var url = 'consulta.php';
$.ajax({
url: url,
type: 'GET',
datatype: 'json',
beforeSend: function(resultado){
$('.mensagem').html('Carregando');
},
success: function(resultado){
for(var i = 0; i < resultado.length; i++){
items += resultado[i].nome + '<br>';
}
$('.info').html(items);
},
fail: function(resultado){
$('.mensagem').html('ERRO NO CARREGAMENTO');
},
complete: function(resultado){
$('.mensagem').html('Tudo Pronto');
}
})
}