1
Guys, I’m just trying to list the names I have in the bank, but the message undefined
, can anyone help? Below is jquery + the query to the bank.
jQuery:
<body>
<script>
$(document).ready(function() {
$('#relatorio').click(function(event) {
$.ajax({
type: 'post',
datatype: 'json',
url: 'ajax.php',
success: function(retorno){
for (var i = 0; i < retorno.length; i++) {
console.log(retorno[i].nome);
};
}
})
});
});
</script>
<input type="submit" name="Relatorio" value="Relatorio" id="relatorio">
</body>
Consulted at the bank:
<?php
$conect = conecta();
$select = seleciona($conect);
echo json_encode($select);
function conecta() {
$server = "localhost";
$usuario = "root";
$senha = "";
$database = "teste";
$conexao = mysqli_connect($server, $usuario, $senha) or die();
mysqli_select_db($conexao, $database);
return $conexao;
}
function seleciona($conect) {
$guarda = array();
$query = "SELECT * FROM teste";
$executa = mysqli_query($conect, $query);
$i = 0;
while ($resultado = mysqli_fetch_array($executa)) {
$guarda[] = array('nome'=> (utf8_encode($resultado['nome'])));
}
return $guarda;
}
?>
Welcome to Stack Overflow in English, please avoid cashier and make more detailed headlines. I hope you get the result.
– Guilherme Nascimento
Where does it lead
undefined
?– Felipe Avelar
The return, when I print on the console
– Jefferson Santos
@Jeffersonsantos Response code has been modified.
– Guilherme Nascimento
Perfect, how do I print on the body of the page? Thank you very much for the help, can you explain to me what parts of codes inserted?
– Jefferson Santos
Good evening, I wonder if any of the answers helped you, if not please comment on what you think is missing.
– Guilherme Nascimento