views:

77

answers:

2

I may be looking at this all wrong.

But, I am trying to use the jquery ui autocomplete.

I want to pass it a url and it will get the suggestions from there.

my questions are
1: how do i specify the url?
2: how do i format the response?

+1  A: 

On the jquery UI page you have a complete demo with different examples, that should be enough I think. Here's the url.

Claudio Redi
-1 this is a comment. If this is an answer, it would have address the question of the OP.
Reigel
@Reigel: examples on that page are quite simple and they address the user problems. Not sure why you think that this should be a comment. The user didn't know about this url and (according his latest comment) IS useful for him.
Claudio Redi
@Claudio - I got this comment (and a downvote for good measure) from a moderator of SO sometime back for an answer of mine. `The identification of duplicates/answering the question with other URLs should be done with a comment.`
ShiVik
@ShiVik: Seems that the moderator meant that you should not answer with a link to another question on SO. This is not the same case :) (I'm pasting an external link)
Claudio Redi
ShiVik
I'm not linking to a random link I found on google I'm linking to the official documentation. Anyway, I get your point. Thanks man.
Claudio Redi
@Claudio - +1. Your point is valid as well. :)
ShiVik
@ShiVik: +1 for you too. Your point is valid too and your answer is good :)
Claudio Redi
+2  A: 

This should get you started with specifying the URL part.

First create an input field to attach the autocomplete plugin to.

<input type="text" name="query" />

Then use this javascript to attach the autocomplete to the input box just created.

   $("#query").autocomplete({
       source: "/suggestions/get/",
       select: function(event, ui) {
          $("#new-field").val(ui.item.value);
       }
    });

The request uri will be something like this...

/suggestions/get/?term={selection}

selection represents the selection made in autocomplete.

Now on your server side you need to parse the uri and use the value of parameter term to do whatever you want - search the database for the selected choice, or something else.

ShiVik