开发者

autosuggestion ASP classic+ajax

anyone can guide me how to create autosuggestion开发者_Python百科 function..same like link below. http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html

thanks


I did this with the jQuery UI autocomplete widget.

I used the widget for all of the styling, but for the information source I used a .asp page that ran a SQL query based on the characters that had already been typed into the box.

So, when someone typed 'ca' into the box, on key release the .asp page would load with a SQL query of "Select keyword where keyword like 'ca%'" and so on.

The jQuery UI widget would then update the autocomplete based on the top suggestions from the query.

You can see it in action in the header of http://www.constructionequipmentguide.com.


Here's some JS/ASP-Classic that queries a database for possible completions, using the Customer table in the AdventureWorks2008LT sample database available from Microsoft.

<%@ language="Javascript" %>

<script language="javascript" runat="server" src='json2.js'></script>
<script language="javascript" runat="server" src='stringExtensions.js'></script>
<script language="javascript" runat="server">

(function() {

    queryDb = function(like) {
        var conn, rs, result = [], C, rec;
        conn = new ActiveXObject("ADODB.Connection");

        conn.ConnectionString =
            'Provider=SQLOLEDB.1;' +
            'Integrated Security=SSPI;' +
            'Persist Security Info=False;' +
            'Initial Catalog=AVWKS2008LT;' +
            'Data Source=.\\SQLEXPRESS';

        conn.Open();
        rs = new ActiveXObject("ADODB.Recordset");
        var query =
            'SELECT distinct Lastname as lname ' +
            'FROM SalesLT.Customer ';
        if (like !== null) {
            query += "WHERE LastName like '" + like + "%' ";
        }

        rs.Open(query, conn, 1, 3);
        while(!rs.EOF) {
            // retrieve the 0th field
            result.push(rs.Fields(0).Value.trim());
            rs.MoveNext();
        }
        conn.Close();
        return result;
    };

}());


try {
    var t = Request.QueryString('token') + '',
        token = (t == 'undefined') ? null : t,
        r = queryDb(token);
    Response.Write(JSON.stringify(r));
}
catch(e) {
    Response.Write(e.message);
}

</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜