我在这里实施购物应用程序。使用自动完成功能搜索产品无效。这是整个代码。
的index.php
<form class="navbar-form navbar-left" action="search.php">
<div class="input-group" style="width: 650px;padding-left:150px; ">
<input type="text" class="form-control" placeholder="Search Product Here..." name="search_text" id="search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
<script>
$(document).ready(function(){
$('#search').autocomplete({
source : 'search_text.php',
minLength : 1,
autoFocus : true
});
});
</script>
用于从数据库中获取数据 的 search_text.php
<?php
include 'db.php';
if (isset($_GET['search_text'])) {
$sql = "select * from product where product_name like '%$_GET[search_text]%'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$array = array();
while( $row = mysqli_fetch_assoc($result)) {
$array[] = array( 'label' => $row['product_name'] , 'value' => $row['product_id'] );
}
echo json_encode ($array);
}
}
?>
任何人都可以帮我找到它无法正常工作的原因吗?