您好我编写的代码使用jQuery自动完成,但jQuery自动完成无法从MySQL使用我的PHP代码获取数据的输入文本。
我的代码有什么问题?下面
是我的javascript代码JQuery自动完成无法从数据库中获取值
<link href="_style/css/smoothness/jquery-ui-1.8.17.custom.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="_scripts/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="_scripts/js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript">
$(function() {
$("#autocomplete").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
log(ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value);
}
});
});
</script>
<body>
<input type="text" id="autocomplete" />
</body>
,这是我的PHP代码:
<?php
include "Connect.php";
$term = trim(strip_tags($_GET['term']));
$qstring = "SELECT pName as value,pID FROM patient WHERE pName LIKE '%".$term."%'";
$result = mysql_query($qstring, $connection);//query the database for entries containing the term
while ($row = mysql_fetch_array($result))//loop through the retrieved values
{
$row['pName']=htmlentities(stripslashes($row['pName']));
$row['pID']=(int)$row['pID'];
$row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
?>
帮助我解决我的代码问题!
你的php脚本是否返回数据? – tftd 2012-02-02 23:41:25
我检查我的php代码没有自动完成编辑文本,并看到我的PHP代码正常工作! – 2012-02-03 00:23:17