views:

79

answers:

3

I am currently using this autocomplete plugin. It's pretty straightforward. It accepts a URL, and then uses that data to perform an auto-complete.

This is my code to auto-complete it.

autocompleteurl = '/misc/autocomplete/?q='+$("#q").val()
$("#q").autocomplete(autocompleteurl, {multiple:true});

If someone types "apple", that autocompleteurl page will return this result:

apple store,applebees,apple.com,apple trailers,apple store locator,apple vacations,applebees menu,apple iphone,apple tablet,apple tv

However, for some reason, when I actually use this auto-complete, everything is junked together. The plugin treats the entire page as a one big string, instead of separating the commas and treating them as individual items.

Can someone tell me what options I need to put in order to treat them as individual items? I've tried many options but none work.

+2  A: 

From the manual (http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url%5For%5Fdataoptions)

A value of "foo" would result in this request url: my_autocomplete_backend.php?q=foo&limit=10

The result must return with one value on each line. The result is presented in the order the backend sends it.

From what you have posted it seems like you have it comma separated.

Tjofras
So, I have to separate it by <br/>?
TIMEX
No just a plain newline
Tjofras
echo "\n"; between the individual entries
namespaceform
A: 

The plugin automatically adds the q to the querystring and uses the current value of the text box as the value.

This should be sufficient as long as you're returning the data in the correct format:

$("#q").autocomplete('/misc/autocomplete/', {multiple:true});
joshperry
TIMEX
A: 

@alex I'm getting quirky behavior too - for 2/3/4 alphabets.
See http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions .
If you set the minChars option to 2 or 3 it makes things more sane.
There's funny behavior when you have 5 results for "ab" and the same 5 results for "abc" - it does nothing, giving the impression that it is not working!
But it is working and I suspect it has to do with caching options.

namespaceform