【发布时间】:2012-02-02 23:36:19
【问题描述】:
您好,我为使用 jquery 自动完成的输入文本编写代码,但 jquery 自动完成无法使用我的 php 代码从 mysql 获取数据。
我的代码有什么问题?
下面是我的javascript代码
<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脚本返回数据了吗?
-
我在没有自动完成编辑文本的情况下检查了我的 php 代码,并看到我的 php 代码工作正常!
标签: php jquery autocomplete