admin管理员组文章数量:1429061
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 badges2 Answers
Reset to default 6Just 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
本文标签: Buffereddelayed ajax requestskeystrokes using JavaScript and JQuery DatatablesStack Overflow
版权声明:本文标题:Buffereddelayed ajax requestskeystrokes using JavaScript and JQuery Datatables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745479984a2660131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论