admin管理员组

文章数量:1434978

I have a jQuery UI autoplete form that fetched data from remote source, but it bees erratic when connection is slow,(queuing up the requests, and messing up results). How we can hold request from firing until user pauses.

I have a jQuery UI autoplete form that fetched data from remote source, but it bees erratic when connection is slow,(queuing up the requests, and messing up results). How we can hold request from firing until user pauses.

Share Improve this question edited Jul 31, 2012 at 13:08 Andrew Whitaker 126k32 gold badges295 silver badges308 bronze badges asked Jul 31, 2012 at 5:32 ducktypedducktyped 4,5024 gold badges28 silver badges39 bronze badges 2
  • what does "user pause" mean in this context? Can you define it somehow? – eis Commented Jul 31, 2012 at 5:43
  • Would this do the job: stackoverflow./questions/4220126/… – eis Commented Jul 31, 2012 at 5:48
Add a ment  | 

1 Answer 1

Reset to default 7

I think the delay option should work for you:

The delay in milliseconds the Autoplete 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").autoplete({
    /* options */,
    delay: 750
});

Compare the following two examples for instance:

  • Using the default (300 ms): http://jsfiddle/q4Xkd/
  • Using 750 ms: http://jsfiddle/x3EkS/

本文标签: javascriptfire ajax request only when user pauses in jquery UI autocompleteStack Overflow