自动完成扩展器在 PHP 中不起作用


auto complete extender not working in PHP

这个自动完成扩展器工作正常,但我不知道它停止工作的原因是什么,没有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();
}

?>

搜索EAN.php可以在这里检查.live链接和自动完成,这是不工作的可以检查 这里

  • 您的echo $qstring;在您的PHP脚本中。注释掉!

抱歉,问题解决了,这是我的错误,我回显查询以检查它,但忘记评论它。 这就是它不起作用的原因。

我注释掉

//echo $qstring; in searchEAN.php file 

及其现在的工作

谢谢