Simple jQuery autocomplete execution

I made a simple autocomplete implementation that would call ajax and load a hit list. Here is jsfiddle

http://jsfiddle.net/83hJw/

This, of course, only shows a warning saying β€œOK” when the timer expires

You will notice that it resets the timeout to allow you to finish typing what you want, that is, if you pause for 0.3 seconds while typing, it will then search to not request the server too many times

I also need to run it only if the number of characters exceeds 4 characters.

Simply put, I want to know if there is a better way to do this in jQuery?

+4
source share
4 answers

Try the jQuery UI autocomplete widget . It supports delay and minLength parameters out of the box.

+3
source

I don't think your implementation has something wrong, but the jQuery user interface has an autocomplete implementation . If you are already using jQuery UI, why reinvent the wheel.

+1
source

Use jQuery UI auto-completion: http://jqueryui.com/demos/autocomplete/

+1
source

Personally, I would say that it is best to start showing examples from the first keystroke and make sure that the results shown are relative and sorted by popularity. This can help users find what they are looking for quickly and with fewer hits.

0
source

Source: https://habr.com/ru/post/1384367/


All Articles