problem with emphasis on jquery autocomplete

Asked

Viewed 851 times

0

I have a UTF-8 problem in my code. I have a input text with autocomplete (jquery function) that works ok with results coming from Mysql, but when a word is accented the accented letter appears a question mark(?). Follows my code:

return cliente_process.php

<?php require_once("conexao/conexao.php"); ?>
<?php
$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends

$qstring = "SELECT clienteNome as value,clienteId as id FROM cliente WHERE clienteNome LIKE '%".$term."%' LIMIT 10";

 $consulta_tr = mysqli_query($conecta, $qstring);
    if(!$consulta_tr) {
        die("erro no banco1");
    }

while ($row = mysqli_fetch_array($consulta_tr,MYSQL_ASSOC))//loop through the retrieved values
{
        $row['value']=htmlentities(stripslashes(utf8_decode($row['value'])));
        $row['id']=(int)$row['id'];
        $row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
?>

function js

$(document).ready(function() {

        $('#clientes').autocomplete({
        source: 'php/retornar_cliente_processo.php',
        minLength: 1,   

          select: function(event, ui) {

            $('#clienteId').val(ui.item.id);
            $('.form-control').removeAttr("disabled");  
            $('#clientes').attr("disabled", "disabled");
            $('#alteraNome').removeAttr("disabled");        
                 },
            }); }

html

 <form class="form-horizontal" id="formCad">

      <input type="hidden" name="clienteId" id="clienteId" placeholder="ID">   

          <div class="form-group">
              <div class="col-md-12">
                  <label for="clienteNome" class="control-label">Nome do cliente</label>

                  <div class="input-group">
                      <input type="text" autocomplete="off" name="clienteNome" id="clientes"  class="form-control" placeholder="Nome do cliente" required>

                  </div>

            </div>
          </div>
  • 1

    put in the head of html <meta charset="UTF-8">

  • I put it on but nothing’s changed

  • See if this helps: http://answall.com/a/120835/43292

  • did not help :(((

  • Take a look at your mysql, make a select in the same database to see if the data are with the encounter correct.

  • it’s all right. I realized that if I change this line: $Row['value']=htmlentities(stripslashes(utf8_decode($Row['value'])); for Ncode it appears strange characters.. and Decode it appears a question mark

Show 1 more comment

2 answers

0

solved my problem by changing the line

$row['value']=htmlentities(stripslashes(utf8_decode($row['value'])));

for

$row['value']=stripslashes(utf8_encode($row['value']));

0

realized that you use utf8-Decode-Encode have you considered changing the language of the database I don’t know if I would solve it but it gets much better

OBS:

    $con =  mysqli_connect("localhost","meu_user","meu_password","meu_db");
    mysqli_set_charset($con, 'utf8');

mysqli_set_charset is msm with guidance

there would be your line:

$row['value']= mysqli_real_escape_string($con, $row['value']]);

http://php.net/manual/en/mysqli.real-escape-string.php

http://php.net/manual/en/mysqli.set-charset.php

Browser other questions tagged

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