Skip to content

Instantly share code, notes, and snippets.

@varequan
Created August 21, 2019 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varequan/6f3dc27b9025ae022a19786b0f214658 to your computer and use it in GitHub Desktop.
Save varequan/6f3dc27b9025ae022a19786b0f214658 to your computer and use it in GitHub Desktop.
jquery实时搜索限制ajax发送频率
function getSearchText(){
var btn = true
$('.searchContent').off('input').on('input',function(){
if(timer){
clearTimeout(timer)
}
if(!btn){
return;
}
btn = false;
var that =this;
var timer=setTimeout(function(){
btn = true
var keyword = $(that).val();
if(keyword == ''){
return;
}
var param = 'keyword='+keyword;
xhr.get(SITE_URL + 'supplychain/model/keyword', param, function(res){
console.log(res);
});
},500);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment