Error ajax return when accent

0

I have a table that when I add some text that contains an accent adds all the other texts of that same condition. already tried several ways to use UTF-8 that I found on the net but none worked and I noticed in console.log () the following error only if you have any item in the table with an accent: "Uncaught SyntaxError: Unexpected end of input" and if it clears something else from the table (where it does not contain any words with an accent) I have return normally.

  

return_data.php

<?php 

    if ( isset($_POST['date']) ) {
    $date = $_POST['date'];
    } 
    $id_dentista = $_POST['id_dentista'];



    $conecta = mysqli_connect("localhost","root","","odonto");
    mysql_query("SET NAMES 'utf8';");
    $selecao = "SELECT * from agenda WHERE dataAgenda = '{$date}' AND dentistaId = '{$id_dentista}' ORDER BY horaAgenda ";
    $categorias = mysqli_query($conecta,$selecao);


    $retorno = array();
    while($linha = mysqli_fetch_object($categorias)) {
        $retorno[] = $linha;
    };  



    echo json_encode($retorno);

    // fechar conecta
    mysqli_close($conecta);
?>
    
asked by anonymous 18.12.2015 / 22:25

1 answer

2

To solve the charset problem use the function:

mysqli_set_charset()

This function is used to correctly set the character types used, in your case I would advise you to do this:

$conecta = mysqli_connect("localhost","root","","odonto");
$selecao = "SELECT * from agenda WHERE dataAgenda = '{$date}' AND dentistaId = '{$id_dentista}' ORDER BY horaAgenda ";
mysqli_set_charset($conecta, 'utf8');
$categorias = mysqli_query($conecta,$selecao) or die(mysqli_error());
    
18.12.2015 / 22:50