我一直在尝试进行自动填充(从数据库中获取数据),虽然我在点击搜索栏时遇到编码问题,但它会以不良编码显示地点名称
以下代码:
$autocomplete= $db->query("
SELECT DISTINCT Helyseg FROM M_munka
WHERE
Publikus = '1' AND
Aktiv = 1 AND
Jovahagyott = 1 AND
Helyseg!='null'
");
$autocomp_q= $autocomplete->json();
$json = json_encode($autocomp_q);
function fetchAllArray(){
$Data = array();
if( !$this->is_empty() ){
$this->reset();
while($row = mysqli_fetch_assoc($this->result)){
$ata[] = array_map('htmlentities',$row);
}
}
return $Data;
}
function json(){
$Data = $this->fetchAllArray();
return json_encode($Data);
}
$(function () {
//$json fájl - json_encoding data
var availableData = <?php echo $json;?>;
var myObject = JSON.parse(availableData);
$('#tags').autocomplete({
source: function (request, response) {
var re = $.ui.autocomplete.escapeRegex(request.term);
var matcher = new RegExp("^" + re, "i");
response($.grep(($.map(myObject, function (v, i) {
return {
label: v.Helyseg,
value: v.Helyseg
};
})), function (item) {
return matcher.test(item.label);
}))
}
});
});
我的猜测是JSON.PARSER破坏了编码(图片结果如下)。