Php 自动完成中没有输出
我使用autocomplete实现了一个类似谷歌的搜索,当我键入搜索内容时,搜索建议会出现在下拉列表中 我的代码的输出Php 自动完成中没有输出,php,jquery,Php,Jquery,我使用autocomplete实现了一个类似谷歌的搜索,当我键入搜索内容时,搜索建议会出现在下拉列表中 我的代码的输出 HTML <td width="155" bgcolor="#999999">Client Name</td> <td width="218" bgcolor="#999999"><input type="text" name="clientname" id="clientname" class="forinput
HTML
<td width="155" bgcolor="#999999">Client Name</td>
<td width="218" bgcolor="#999999"><input type="text" name="clientname" id="clientname" class="forinput" /></td>
我想要实现的目标我检查数据库连接是否正确。谁能解释一下我做错了什么?我遗漏了什么吗?我不认为你返回的结果根据什么是有效的 现在,您正在构建一个数组数组,您应该只返回值(假设
标签
和值
相同,即客户端的名称):
还请注意有关已弃用的
mysql.*
函数和sql注入的注释。您需要调试此函数并提供更多细节。您是否正在观看浏览器的控制台(F12)?在网络选项卡中,可以看到对getautocomplete.php的AJAX请求发生了吗?是否正在发送术语
?另请参阅。您的查询易受注入攻击,因为$term
未被扫描。另外,请确保在PHP端启用并打开了错误报告<代码>错误报告(E_全部);ini设置(“显示错误”,1);
<script type="text/javascript">
$(document).ready(function() {
$( "#clientname" ).autocomplete(
{
source:"getautocomplete.php",
minLength:1
})
});
</script>
..databaseconnection
$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends
$qstring = "SELECT clientname FROM client WHERE clientname LIKE '%".$term."%'";
$result = mysql_query($qstring);//query the database for entries containing the term
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
$row['clientname']=htmlentities(stripslashes($row['clientname']));
$row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
// $row['clientname']=htmlentities(stripslashes($row['clientname']));
$row_set[] = htmlentities(stripslashes($row['clientname'])); //build an array