0

我有我的索引页面 INDEX.html 和一个 PHP 页面 TEST.php,然后是一个自动提示的 javascript 代码。

我正在尝试创建一个自动建议搜索字段。

我没有得到自动建议输出。

NO RESULT FOUND显示。

有人请帮助我在http://code.drewwilson.com/entry/autosuggest-jquery-plugin中显示自动建议。

<link href="css/autoSuggest.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="jquery.autoSuggest.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" name="form1" method="post" action="">
        <label for="q"></label> <input style="width: 300px;" type="text"
            name="q" id="q" />
        <script type="text/javascript">  
     $(document).ready(function(){      
     $("input[type=text]").autoSuggest("test.php",{minChars: 2, matchCase: false});});  
     </script>
    </form>
</body>
</html>

PHP看起来像这样:

<?php include("script/core/dbcon.php");  
 $input = $_REQUEST['q'];  
 $data = array();  
 // query your DataBase here looking for a match to $input  
 $query = mysql_query("SELECT * FROM user WHERE username LIKE '%$input%'");  
 while ($row = mysql_fetch_assoc($query)) {  
 $json = array();  
 $json['value'] = $row['id'];  
 $json['name'] = $row['username'];  
 $data[] = $json;  
 }  
 header("Content-type: application/json");  
echo json_encode($data);  
 ?>
4

1 回答 1

1

jQuery 现在有一个 AutoComplete 方法,它会做同样的事情

你也应该更换

$("input[type=text]").auto----

$("#q").auto-----
于 2012-05-08T16:34:13.587 回答