I have Ajax which loads data from the database and in type json:
$.ajax({
type:'post',
dataType: 'json',
url: '../model/dao/CursoDao.php?acao=1',
success: function(dados){
for(var i=0; dados.length > i; i++){
$('#listaCursos').append('<a href="sala_view.php?idcurso='+ dados[i].id + '" class="btn btn-primary texto-grande botao-nivel sombra">' + dados[i].titulo +'</a>');
}
}
});
The PHP function:
public function listaCursoAjax() {
$sqlCurso = $this->conexao->prepare('SELECT * FROM curso');
$sqlCurso->execute();
while($linha = $sqlCurso->fetch(PDO::FETCH_ASSOC)) {
$vetor[] = array_map('utf8_encode',$linha);
}
echo json_encode($vetor);
}
The problem is that phrases with an accent are being encoded: