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

Buffereddelayed ajax requestskeystrokes using JavaScript and JQuery Datatables - Stack Overflow

programmeradmin0浏览0评论

I am currently prototyping an enterprise web app which will include a quick search screen. This screen uses JQuery and Datatables to provide a tabular view of the search results. Searches are performed based on matches to string entered in a text field. Each time a key is pressed, a new AJAX request is sent back to a servlet, the search is performed (across a large database) and results are returned via JSON to be updated on the table.

The search on the database is a costly operation. A lot of times when a user is typing, say, a name, they would type a number of letters in quick succession. This will result in multiple searches being triggered in the backend, sometimes unnecessarily.

I was wondering if there is a way of cleverly buffering those request. For example, if a user is typing "Jonathan", do not send a request for J, Jo, Jona, Jonath, ... if they are all typed within a time limit of each other, and only send the request when there is a sufficient gap in typing, i.e. when the letter n at the end is typed.

I know this will cost a slight delay but it may be a worthy promise.

Do you think think this makes sense? Is there an existing pattern/library for such operations? Does it cause usability issues that I haven't thought of?

Greatly appreciate your opinions!

I am currently prototyping an enterprise web app which will include a quick search screen. This screen uses JQuery and Datatables to provide a tabular view of the search results. Searches are performed based on matches to string entered in a text field. Each time a key is pressed, a new AJAX request is sent back to a servlet, the search is performed (across a large database) and results are returned via JSON to be updated on the table.

The search on the database is a costly operation. A lot of times when a user is typing, say, a name, they would type a number of letters in quick succession. This will result in multiple searches being triggered in the backend, sometimes unnecessarily.

I was wondering if there is a way of cleverly buffering those request. For example, if a user is typing "Jonathan", do not send a request for J, Jo, Jona, Jonath, ... if they are all typed within a time limit of each other, and only send the request when there is a sufficient gap in typing, i.e. when the letter n at the end is typed.

I know this will cost a slight delay but it may be a worthy promise.

Do you think think this makes sense? Is there an existing pattern/library for such operations? Does it cause usability issues that I haven't thought of?

Greatly appreciate your opinions!

Share Improve this question edited Sep 5, 2011 at 15:11 Ashkan Aryan asked Sep 5, 2011 at 14:48 Ashkan AryanAshkan Aryan 3,5344 gold badges31 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Just in case someone looking at a similar problem: after Spike's ment I checked datatables plugins and there's something that does exactly what I wanted above: see fnSetFilteringDelay

You could use the jquery-ui framework's autoplete function, which has a delay option that does exactly what you're looking for.

http://jqueryui./demos/autoplete/#option-delay

发布评论

评论列表(0)

  1. 暂无评论