你可以做这样的事情,假设你很高兴在页面加载时填充列表并且不想实时查找服务器:
<%
' server-side ASP
Dim rs, data_source, ado
Set ado = CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
ado.ConnectionString = MM_rtasql_STRING
ado.Open
rs.ActiveConnection = ado
rs.CursorType = 2
rs.CursorLocation = 2
rs.LockType = 3
rs.Open "select field1 from mydatabase where whatever > soandso"
' build up a string which looks like a Javascipt array (eg "['val1','val2']")
' instead of a loop, you could use rs.GetString(), which is quicker
dim s: s = "["
do until rs.EOF
s = s & "'" & CStr(rs("field1")) & "',"
loop
rs.Close
' remove trailing comma and complete array string
s = left(s, len(s) - 1) & "]"
%>
<!-- client-side -->
<script type="text/javascript">
$(document).ready(function() {
$("textbox-selector").autocomplete({
source: <%=s %> // ASP insert of javascript array string
});
});
</script>
我没有测试过这个和我从他们的例子中得到的 jQuery:http: //jqueryui.com/autocomplete/