自动完成扩展程序不能在PHP中工作

时间:2012-08-14 10:57:47

标签: php jquery jquery-autocomplete

这个自动完成扩展程序工作正常,但我不知道它停止工作的原因,没有javascript错误即将到来。这是我的代码

<script src="scripts/jquery-1.4.1.js" type="text/javascript"></script>

    <script src="scripts/jquery-ui.min.js" type="text/javascript"></script>
    <link href="scripts/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    $(function() {

    $("#autocomplete").autocomplete({   
      source: "searchEAN.php",
      minLength: 2,//search after two characters
      select: function(event,ui){
       // alert ($value.$id);
       alert (ui.item.value);
      //do something, like search for your hotel detail page
      }  
    });
    });
    </script>
</head>
<body>

<div class="demo">
  <div class="ui-widget">
     <label for="autocomplete">Hotel Name: </label>
     <input id="autocomplete" name="autocomplete"/>
  </div>
</div>

这是searchEAN.php页面代码。当我通过将术语作为查询字符串

直接运行此页面时返回数据
<?php

include_once('config.php');

if (isset($_GET['term'])) {
$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends    
$qstring = "SELECT Distinct CONCAT(City,',',StateProvince,',',Country) AS value,EANHotelID AS id FROM ActivePropertyList WHERE City LIKE '%".$term."%' GROUP BY value limit 0,10 ";
echo $qstring;
$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['value']=htmlentities(stripslashes($row['value']));
     $row['id']=(int)$row['id'];
     $row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
mysql_close();
}


?>

searchEAN.php可以在这里查看。活动链接和自动完成功能无法检查here

2 个答案:

答案 0 :(得分:1)

  • 您的echo $qstring;脚本位于PHP脚本中。评论出来!

答案 1 :(得分:0)

抱歉,问题解决了,这是我的错误,我回应查询检查它,但忘了评论它。这就是它无法工作的原因。

我评论了

//echo $qstring; in searchEAN.php file 

及其现在的工作

谢谢

相关问题