Good people, my problem is this. I have a JS function to do a query in the mysql database via ajax, it returns apparently correctly but when I try to access the value of "undefined" This is an alert (response); being "response" ajax response
HoweveratthetimeItrytoaccessexampleresponse[0].aluno,resultisundefined.
JS
var hora = $this.find('h1').text();
$.ajax({
type: "POST",
dataType: "html",
url: "alunos.php",
data: { 'hora': hora},
success: function(response){
alert(response);
// for(var i=0;response.length>i;i++) {
// console.log( response[i].nome);
// }
}
});
<?php
header("Content-Type: text/html; charset=UTF-8");
$mysqli = new mysqli('localhost', 'root', 'vagrant', 'webfit');
$hora = filter_input(INPUT_POST, 'hora');
$sql = "SELECT aluno.nome as aluno from aula, aluno_aula,aluno where aluno.id = aluno_aula.aluno_id AND aluno_aula.aula_id=aula.id AND aula.horaini='{$hora}';"; //monto a query
$query = mysqli_query($mysqli,$sql); //executo a query]
while($row = mysqli_fetch_assoc($query)){
$vetor[] = array_map('utf8_encode', $row);
}
echo json_encode($vetor);
?>