jQuery的自动完成,我可以有previous AJAX调用停止时,我提出一个新的?自动完成、jQuery、AJAX、previous

2023-09-10 13:23:37 作者:眼里有星辰

现在我使用jQuery自动完成的,但我发现了一个性能相关的问题 - 如果我输入ABC,它会扫描通过'一',由'AB',并通过'ABC',在一次,我怎么可以停止previous'A','AB'当AJAX调用是由ABC?

Now I'm using jQuery auto-complete, but I found a performance-related issue - if I input 'abc', it will be scanning by 'a', by 'ab', and by 'abc', at a once, how can I stop the previous 'a', 'ab' when ajax calling is doing searching by 'abc'?

类似的情况 - , 我使用jQuery的数据表,并希望做一些搜索类的,我输入一些搜索(调用搜索Web方法),并点击按钮 - 搜索3次,一次,或更改只是当我点击搜索搜索文本,并提出一个新的搜索,我怎么能停止previous无用的AJAX调用?

The similar case is -, I use jQuery DataTables, and want to do some searching like, I typed something to search (call search web method), and clicked button - 'Search' 3 times at a once, or changed search text just when I clicked 'Search', and raise a new search, how can I stop the previous useless ajax calling?

希望我自己清楚。 先谢谢了。

Hope I made myself clear. Thanks in advance.

推荐答案

假设你正在使用 jQuery UI的自动完成:

您可以前开始搜索指定字符串的最小长度。 (默认为3我猜的) 您还可以指定最后的按键和Ajax调用之间的延迟。通常2-300ms应该做的。 AjaxQueue 可能会帮助你清理一些东西。不知道如何(我从来没有需要的话),但值得一试:) You can specify the minimum length of string before starts searching. (default is 3 I guess) You can also specify the delay between last keystroke and ajax call. Usually 2-300ms should do. AjaxQueue might help you to clean some stuff. Dunno how (I never need it), but worth a shot :)
 
精彩推荐
图片推荐