2012-05-08 26 views
0

我有我的索引頁面INDEX.html和PHP頁面TEST.php,然後是一個自動提示JavaScript代碼。Drew Wilson Auto Suggest插件不工作

我想做一個自動建議搜索字段。

我沒有得到autosuggest輸出。

僅顯示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); 
?> 
+1

誰是德魯威爾遜?也請正確格式化您的問題。 – Cylindric

+1

[德魯威爾遜自動提示插件](http://code.drewwilson.com/entry/autosuggest-jquery-plugin) – nikki

回答

1

的jQuery現在已經得到了一個自動完成的方法,這將做同樣的

你也應該

取代

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

$("#q").auto-----