最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - fire ajax request only when user pauses in jquery UI autocomplete - Stack Overflow

matteradmin5PV0评论

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/
Post a comment

comment list (0)

  1. No comments so far