Return ajax error when have accent

Asked

Viewed 374 times

0

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

ret_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);
?>

1 answer

2


To solve the charset problem use the function:

mysqli_set_charset()

This function is used to correctly set the types of characters used, in your case I would advise you to do so:

$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());
  • very good guy.. I tried thousands of ways to set the utf8 and that was the only solution!! thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.