最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin10浏览0评论

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/
发布评论

评论列表(0)

  1. 暂无评论