我正在研究一個ASP.NET應用程序,我需要jQuery AutoComplete。當我在txt63輸入框輸入數據時(,以及在使用像txt63這樣的名字之前,我知道,我知道......但它不是我的電話:D),目前沒有任何事情發生。無法讓jQuery AutoComplete與外部JSON一起工作
這裏是我的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工作圖書館。我試圖讓它與新的一起工作,因爲我聽說「dev」CDN將會過時。
任何幫助或方向將不勝感激。
我認爲txt63是一個崇高的名字發表評論,我的名字我的第63個孩子這個歡樂的名字,並指責另一個我不能命名爲別的:d – Gabriel 2010-05-31 05:12:22
剛澄清。網站所有者已經構建了需要與此應用程序接口的應用程序和數據結構。數據庫表只是一堆數字50 - 250或像這樣一些愚蠢的東西。如果我要使用名字,那麼我必須爲下一個將名稱映射到數據庫的人建立一個參考指南......這樣做更有意義。 – 2010-05-31 05:16:06