我不知道我做錯了。我試圖用自動完成使用JSON,但我總是得到完整的數據。我期望用戶輸入的過濾數據。獲取過濾結果的jQuery UI自動完成
JS:
$("#tags").autocomplete({
source: "/script.php",
minLength: 2,
select: function(event, ui) {
var url = ui.item.id;
if(url != '#') {
location.href = '/blog/' + url;
}
},
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
PHP:
$result = $paed_db->prepare('SELECT data FROM table');
$result->execute();
$a_json = array();
while($data = $result->fetch(PDO::FETCH_OBJ)) {
$a_json_row["value"] = $data->data;
array_push($a_json, $a_json_row);
}
$json = json_encode($a_json);
print $json;
exit;