开发者

JQuery autocomplete does not like numbers in this example

I have a jquery exam开发者_开发技巧ple that works when i enter letters but does not work when i enter numbers:

<script>
    $(function() {
        $("#box1").autocomplete({
            url: 'test-search3.ashx?s=mrn'
        });
    });
</script>

<form>
 <input type="text" id="box1">
</form>

Here is the code for the ashx page:

<%@ WebHandler Language="VB" Class="test_search" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text

Public Class test_search : Implements IHttpHandler

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/plain"
        Dim qString As String = context.Request.QueryString("q")
        Dim typeString As String = context.Request.QueryString("s")
        Dim sqlStr As String = ""

        Try
            Dim conn As SqlConnection = New SqlConnection
            conn.ConnectionString = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            Dim cmd As SqlCommand = New SqlCommand
            If typeString = "mrn" Then               
                sqlStr = "select Pat_ID, Name=LastName + ', ' + FirstName " & _
                " from Patients p Where Active=1 " & _
                " and p.MRN like '" & qString & "%' order by lastname"
            Else
                sqlStr = "select Pat_ID, Name=LastName + ', ' + FirstName " & _
                " from Patients p Where Active=1 " & _
                " and Lower(LastName) like '" & qString & "%' order by lastname"
            End If

            cmd.CommandText = (sqlStr)
            cmd.Connection = conn
            Dim sb As StringBuilder = New StringBuilder
            conn.Open()
            Dim sdr As SqlDataReader = cmd.ExecuteReader
            'sb.Append(qString & "/" & typeString).Append(Environment.NewLine)
            While sdr.Read
                sb.Append(sdr("Name") & "|" & sdr("Pat_ID")).Append(Environment.NewLine)
            End While
            conn.Close()
            context.Response.Write(sb.ToString)
        Catch ex As Exception
            context.Response.Write("Error: " & ex.ToString)
        End Try

    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class


There are lot of jquery autocomplete plugins which work fairly well.

This plugin is a good one.

For other jQuery Plugins.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜