我按照示例http://jqueryui.com/autocomplete/
进行了操作但是我想要一个来自数据库的动态数组而不是固定数组
我几乎让它工作了,但是当我输入它时不会过滤结果,即使我输入了一个在数组中不存在的字母,它仍会显示完整的列表。
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”,“LENOVO”,“SONY”]
任何想法我做错了或错过了
答案 0 :(得分:0)
将Jquery更改为以下内容并立即正常工作
<script>
$(function() {
$.getJSON("autocomplete.asp", function(data) {
$("#tags").autocomplete({
source: data
});
});
});
</script>