1
我有以下形式使用jQuery UI自动完成从MySQL数据库的建议
<form action="search.php" method="POST">
<input type="text" name="search" id="search-input">
<input type="submit" value="Submit" id="submit">
</form>
的search.php
<?php
require_once 'db.php';
$a = array();
if (isset($_POST['search']) && !empty($_POST['search'])) {
$search_param = trim($_POST['search']);
$slct_search = $db->prepare("SELECT student_name FROM student_details WHERE student_name LIKE ?") or die($db->error);
$slct_search->bind_param('s', $search_param);
$slct_search->execute();
$res = $slct_search->get_result();
if($res->num_rows) {
while ($result = $res->fetch_object()) {
$a[] = $result->student_name;
}
echo json_encode($a);
} else {
echo 'OOPS we had a problem';
}
}
?>
的search.php工作正常。它返回
[ “拉维”, “拉维”]
JS代码
$(function() {
$("#search-input").autocomplete({
source: "search.php",
minLength: 2
});
});
问题是,当我开始在文本框中键入立即显示
没有搜索结果。
我也尝试JQuery UI Autocomplete Search Results do not display
请任何一个答案与实例 – Prakash