0

这个自动完成扩展器工作正常,但我不知道它停止工作的原因,没有 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可以在这里查看 .live 链接和自动完成不起作用可以在这里查看

4

2 回答 2

1
  • echo $qstring;在你的PHP脚本中。评论出来!
于 2012-08-14T11:00:54.033 回答
0

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

我注释掉

//echo $qstring; in searchEAN.php file 

及其现在的工作

谢谢

于 2012-08-14T11:00:48.540 回答