【发布时间】:2023-03-05 00:51:02
【问题描述】:
我想使用 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>
搜索.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 工作正常。它返回
["ravi","ravi"]
JS 代码
$(function() {
$("#search-input").autocomplete({
source: "search.php",
minLength: 2
});
});
问题是当我开始在文本框中输入时立即显示
没有搜索结果。
【问题讨论】:
-
请任何一个例子回答