Avoid multiple autocomplete calls by wrapping it with SetTimeOut
Posted
by pixelboy
on Stack Overflow
See other posts from Stack Overflow
or by pixelboy
Published on 2010-05-03T12:09:45Z
Indexed on
2010/05/03
12:28 UTC
Read the original article
Hit count: 259
Here's my issue : using an autocomplete jQuery plugin, I'd like to avoid multiple ajax requests when user strikes his keynoard by surrounding the
$('#query1').autocomplete({
serviceUrl:'/actions/autocomplete?population=salon',
minChars:3,
maxHeight:300,
width:200,
clearCache:true,
onSelect: function(suggestions,data){ $(".btn1").attr("href", "${pageContext.request.contextPath}/actions/espaceClients?participantId=" + data) }
});
with something like
var search = false;
$('#query1, #query2, #query3').keyup(function(){
if (!search){
search = true;
}
if (search) {
search = false;
autocompleteThem();
}
});
A you can see, above code is stupid, but it kinda shows what i'm trying to do.
In simple words, if user dosen't type anything else in a certain period of time, then you can call autocomplete.
I hope i'm being clear, as my brains are a mess...
© Stack Overflow or respective owner