Created
August 21, 2019 03:06
-
-
Save varequan/6f3dc27b9025ae022a19786b0f214658 to your computer and use it in GitHub Desktop.
jquery实时搜索限制ajax发送频率
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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