2016-07-19 36 views
0

我跟着例子http://jqueryui.com/autocomplete/數據未過濾jQuery的自動完成

但不是一個固定的數組,我想從數據庫

動態數組,我幾乎得到它的工作,但在我鍵入它將不會過濾結果,即使我鍵入數組中不存在的字母,它仍會顯示完整列表。

enter image description here

search.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta charset="utf-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>jQuery UI Autocomplete - Default functionality</title> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> 
<link rel="stylesheet" href="/resources/demos/style.css"> 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
<script> 
$(function() { 
$("#tags").autocomplete({ 
    source: 'http://fullurl/autocomplete.asp' 
}); 
}); 
</script> 
</head> 
<body> 

<div class="ui-widget"> 
<label for="tags">Tags: </label> 
<input id="tags"> 
</div> 

autocomplete.asp

<% 
sConn = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=SERVER; Port=3306; DATABASE=database; UID=username;PASSWORD=password; OPTION=3"  
Set Conn = Server.CreateObject("ADODB.Connection") 
Conn.Open sConn 

sSQL = "SELECT * FROM makes ORDER BY makes ASC;" 

Set rst = Server.CreateObject("ADODB.Recordset") 
rst.CursorLocation = 3 
rst.Open sSQL, Conn, 3, 1 

output = "[" 

DO Until rst.EOF 
output = output & chr(34) & rst("makes") & chr(34) & "," 
rst.movenext 
Loop 

output = left(output,(len(output)-1)) 
output = output & "]" 

Response.Write output 

rst.close 
Conn.Close 
%> 

這是autocomplete.asp的結果: 「ACER」, 「DELL」, 「HP」, 「聯想」, 「SONY」]

我做了什麼錯或漏掉了

回答

0

任何想法將Jquery更改爲以下並現在正常工作

<script> 
$(function() { 
$.getJSON("autocomplete.asp", function(data) { 
    $("#tags").autocomplete({ 
     source: data 
    }); 
    }); 
}); 
</script>