我在jquery的autocomplete中遇到了一些问题。
当我用重音输入一个字母时,结果是“MÁ;THEUS”而不是“MÁTHEUS”
我试着把utf8编码改成解码,然后我得到了“M”?“美国”
遵循我的代码如下
retinar_cliente_processo.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_encode($row['value'])));
$row['id']=(int)$row['id'];
$row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
?>
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格式
<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>
最佳答案
在这里,删除htmlentities(),这就是为什么您得到MÁTHEUS
而不是MÁTHEUS
:
$row['value']=stripslashes(utf8_encode($row['value']));