Can't get jQuery AutoComplete to work with External JSON
- by rockinthesixstring
I'm working on an ASP.NET app where I'm in need of jQuery AutoComplete. Currently there is nothing happening when I type data into the txt63 input box (and before you flame me for using a name like txt63, I know, I know... but it's not my call :D ).
Here's my javascript code
<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);
}
});
});
and here is my HTTP Handler
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
The rest of my ASPX page has the appropriate controls as I had this working with the old version of the jQuery library. I'm trying to get it working with the new one because I heard that the "dev" CDN was going to be obsolete.
Any help or direction will be greatly appreciated.