Evan,
Thank you for responding.
I am looking for a drop down listing of records, (in the current
incarnation) titles of journals, to appear below a text box when the
user enter text into the text box. I feel it would be best to
dynamically load the records as the current database table currently
has over 35,000 title and is expanding.
Here is the code for the pagemethod, and it is on the code behind page
Test.aspx:
<WebMethod(enableSession:=True), ScriptMethod(UseHttpGet:=True,
ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function autoCompleteListing(ByVal name As String)
As String
Dim journalList As New List(Of String)
Dim strJournals As String = String.Empty
journalList.Add(name)
journalList.Add("HERE")
journalList.Add("THERE")
journalList.Add("NOWHERE")
journalList.Add("ANYWHERE")
strJournals = New
JavaScriptSerializer().Serialize(journalList)
Return strJournals
End Function
I can execute the pagemethod, and I do see the desired results as they
occur in FireBug, and by applying the results to a label:
return is ["test","HERE","THERE","NOWHERE","ANYWHERE"]
I was trying to bind the autocomplete to a text box by the following
jQuery code:
$(function() {
$(".txtTitle").autocomplete({
source: function(request, response) {
$.ajax({
url: "Test.aspx/autoCompleteListing",
data: "{ 'name': '" + request.term +
"' }",
dataType: "json",
type: "GET", //have
tried this with "POST"
contentType: "application/json;
charset=utf-8",
dataFilter: function(data) { return
data; },
success: function(data) {
console.log("The data is " + data);
response($.map(data.d, function(item)
{
return {
value: item
}
}))
},
error: function(XMLHttpRequest,
textStatus, errorThrown) {
alert(textStatus);
}
});
console.log("request is " + request);
},
minLength: 2
});
console.log("executed autocomplete");
});
The console.log does display 'executed autocomplete'
But typing 'test' into the txtTitle text box does not fire the
autocomplete; it take a carriage return (pressing the return key) to
initiate any kind of action. In FireBug, it is a "POST" instead of a
"GET". The pathway only goes to /.../.../test.aspx instead of /.../.../
test.aspx/autoCompleteListing?name=%22test%22. But the post does
indicate that the text box does contain 'test'. I would say it is not
executing the pagemethod, but is executing a refresh, thus executing
an updating of an Update Panel with undesirable results.
I have tried the the example of the a local array and applying to the
text box 'txtTitle', and that works for me. The src is pointing to CDN
at dev.jquery.com.
Thank for your help,
Brandon
On Apr 19, 7:52 am, Evan James Bowling <[email protected]> wrote:
> Hello Brandon,
>
> Could you please give me more details about what you are looking for? I
> found the documentation <http://docs.jquery.com/Plugins/autocomplete> and
> demo <http://view.jquery.com/trunk/plugins/autocomplete/demo/> on the jquery
> site. Sharing some of your code might help me to understand better.
>
> Thanks,
> Evan Bowling
>
> On Mon, Apr 18, 2011 at 2:46 PM, Brandon Burch <[email protected]>wrote:
>
> > Afternoon all,
>
> > I have been trying to code an autocomplete with the jQuery
> > autocomplete for a textbox. I would like to have autocomplete's source
> > get its data from a pagemethod. I have already coded the pagemethod on
> > the code behind page, and I am getting the desired results. I would
> > like the results be dynamically created as the text in the textbox
> > changes.
>
> > I have found examples on the net for get the data from .ashx
> > and .asmx, and tried to use them as a starting point for coding a
> > solution since I have only found couple of examples of pagemethod and
> > the autocomplete that have not worked.
>
> > Any help would be greatly appreciated.
>
> > Thanks,
> > Brandon
>
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/[email protected]/
>
> > To search via a non-Google archive, visit here:
> >http://www.mail-archive.com/[email protected]/
>
> > To unsubscribe from this group, send email to
> > [email protected]
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]