gpt4 book ai didi

javascript - 删除 'onKeyUp' 搜索的多个请求

转载 作者:行者123 更新时间:2023-11-29 20:15:42 24 4
gpt4 key购买 nike

这是中止使用“onkeyup”搜索时创建的多个请求的正确方法吗?

(注意:对于多个请求,我指的是为字符串的每个单独字符创建的顺序请求。例如:“Hello”创建 'H'、'He'、...'Hello' - 5 个不同的请求)

var insideReq = false;                      /* Initialise to false */
$('#search').keyup( function() {
var SearchString = $('#search').val();
if((SearchString.length) >= 3) {
if(insideReq == true ) /* Check if somebody is inside */
ajaxReq.abort(); /* If yes, then throw her out */
insideReq = true; /* Inform I am inside */
var ajaxReq = $.get('search.exec.php', {q: SearchString}, function(ajaxContent) {
$('#container-list').html("<img src=\"img\\busy.gif\" class=\"busy-indicator\"/>");
$('#container-list').fadeOut(5);
$('#container-list').html(ajaxContent);
$('#container-list').fadeIn(1500);
insideReq = false; /* Work done; I am going */
});
}
});

最佳答案

看起来不错。很少有代码优化技术可以使您的代码快速执行。

var insideReq = false;                      /* Initialise to false */
$('#search').keyup( function() {
var SearchString = $('#search').val();
if((SearchString.length) >= 3) {
if(insideReq == true ) /* Check if somebody is inside */
ajaxReq.abort(); /* If yes, then throw her out */
insideReq = true; /* Inform I am inside */
var ajaxReq = $.get('search.exec.php', {q: SearchString}, function(ajaxContent) {
$('#container-list')
.html("<img src=\"img\\busy.gif\" class=\"busy-indicator\"/>");
.fadeOut(5);
.html(ajaxContent);
.fadeIn(1500);
insideReq = false; /* Work done; I am going */
});
}
});

关于javascript - 删除 'onKeyUp' 搜索的多个请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6960324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com