我有一个jquery示例,当我输入字母时有效,但在输入数字时不起作用:
<script>
$(function() {
$("#box1").autocomplete({
url: 'test-search3.ashx?s=mrn'
});
});
</script>
<form>
<input type="text" id="box1">
</form>
以下是ashx页面的代码:
<%@ 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