收录日期:2019/10/22 14:30:53 时间:2009-11-10 23:25:33 标签:javascript,jquery,autocomplete,autosuggest

I am using this JQuery autocomplete plugin. It works, and it's simple. But there's a slight problem...

$("#q").autocomplete('/misc/autocomplete/', {autoFill:false,multiple:true, multipleSeparator:''});

When that happens, everytime I push a key into #q, it will call that misc/autocomplete/ website. If I search for cat, it will call that website 3 times. However, instead of calling "c", then "ca", then "cat", it will pass 3 separate characters. Of course, this is not what I want.

misc/autocomplete/?q=c&limit=10&timestamp=1257895405420
misc/autocomplete/?q=a&limit=10&timestamp=1257895405420
misc/autocomplete/?q=t&limit=10&timestamp=1257895405420

I have tried appending the $("#q").val() to the end of the URL part...but no luck. still the same. Can anyone tell me how to fix this auto-complete?

Have you seen the minChars property?

You can pass in a value to specify the minimum number of characters a user has to type before the autocompleter activates.

Did you see the other options you can set too (click on the options tab)

EDIT:

As I pointed out in the comments, you're using a '' for a multiple separator, therefore the plugin assumes that c, a and t are all separate terms to search for. I think that you might want to amend this to something else, possibly ' '

That's not a bug, it's the behavior according to the specified options.

You specified multiple: true making the plugin accept several search terms, but then you define the term separator as multipleSeparator: '', meaning that there isn't any separator and therefore each character is an individual search term, which is probably not what you want, but it's what the plugin is giving you.

Check out the Plugin's Documentation for more details on the options you provided to it.