문제

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?

도움이 되었습니까?

해결책

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.

You should format your response like this...

suggestion1
suggestion2
suggestion3
suggestion4

The suggestions should be on a new line (separated by \n)

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top