I have a jQuery UI autocomplete form that fetched data from remote source, but it becomes erratic when connection is slow,(queuing up the requests, and messing up results). How we can hold request from firing until user pauses.
Asked
Active
Viewed 2,765 times
3

Andrew Whitaker
- 124,656
- 32
- 289
- 307

ducktyped
- 4,354
- 4
- 26
- 38
-
what does "user pause" mean in this context? Can you define it somehow? – eis Jul 31 '12 at 05:43
-
Would this do the job: http://stackoverflow.com/questions/4220126/run-javascript-function-when-user-finishes-typing-instead-of-on-key-up – eis Jul 31 '12 at 05:48
1 Answers
7
I think the delay
option should work for you:
The delay in milliseconds the Autocomplete waits after a keystroke to activate itself. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive.
By default, it's 300 (ms) but you should increase it to suit your needs.
$("#my-input").autocomplete({
/* options */,
delay: 750
});
Compare the following two examples for instance:
- Using the default (300 ms): http://jsfiddle.net/q4Xkd/
- Using 750 ms: http://jsfiddle.net/x3EkS/

Andrew Whitaker
- 124,656
- 32
- 289
- 307
-
And, if you need to, based on logic, you can change the delay during processing - for instance if the queue of multiple requests occurs, add a bit to the delay. – Mark Schultheiss Jul 31 '12 at 13:13