我正在开发一个需要 jQuery AutoComplete 的 ASP.NET 应用程序。目前,当我在 txt63 输入框中输入数据时没有发生任何事情(在你因为使用像 txt63 这样的名称而激怒我之前,我知道,我知道......但这不是我的电话:D)。
这是我的 JavaScript 代码
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.1.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var theSource = '../RegionsAutoComplete.axd?PID=<%= hidden62.value %>'
$(function() {
$('#<%= txt63.ClientID %>').autocomplete({
source: theSource,
minLength: 2,
select: function(event, ui) {
$('#<%= hidden63.ClientID %>').val(ui.item.id);
}
});
});
这是我的 HTTP 处理程序
Namespace BT.Handlers
Public Class RegionsAutoComplete : Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
''# the page contenttype is plain text'
context.Response.ContentType = "application/json"
context.Response.ContentEncoding = Encoding.UTF8
''# set page caching'
context.Response.Cache.SetExpires(DateTime.Now.AddHours(24))
context.Response.Cache.SetCacheability(HttpCacheability.Public)
context.Response.Cache.SetSlidingExpiration(True)
context.Response.Cache.VaryByParams("PID") = True
Try
''# use the RegionsDataContext'
Using RegionDC As New DAL.RegionsDataContext
''# query the database based on the querysting PID'
Dim q = (From r In RegionDC.bt_Regions _
Where r.PID = context.Request.QueryString("PID") _
Select r.Region, r.ID)
''# now we loop through the array'
''# and write out the ressults'
Dim sb As New StringBuilder
sb.Append("{")
For Each item In q
sb.Append("""" & item.Region & """: """ & item.ID & """,")
Next
sb.Append("}")
context.Response.Write(sb.ToString)
End Using
Catch ex As Exception
HealthMonitor.Log(ex, False, "This error occurred while populating the autocomplete handler")
End Try
End Sub
End Class
End Namespace
我的 ASPX 页面的其余部分具有适当的控件,因为我使用的是旧版本的 jQuery 库。我正试图让它与新的一起工作,因为我听说“开发”CDN 将被淘汰。
任何帮助或指导将不胜感激。