jQuery : how to add a delay to an ajax request? -
I have a function that provides a certain amount of data that triggers AJAX while typing.
But, as soon as I type "long" string like "hello my name", every time I make a request (once in 10 times and takes it in 5 seconds) 1 request response).
How to avoid that? (I do not want to use .onblur)
$ (document) .ready (function () {$ ('search input [type = "submit"]'). Hide () ($ ('# Search_keywords' 'ART' ('Action'), {query: this.value + '*'}, function () ($ ('#' ($ #) '$' ('# employment'). Loader '). Hide ();}}}}}})}}
thanks;)
I set a timer on that funnel
event, such as:
$ ('# search_keywords') keyboard (function () {Clear timeout ($. Data (this, 'timer')); $ (this). Data ('timer', set timeout ($ proxy ( Oz, it), 500));}); function search () (if (this.value.length & gt; = 2 || this.value == '') {$ ('# loader'). ); ARRR ('Action'), {query: this.value + '*'}, function () {$ ('# loader) $ (' # jobs ').'). Hide ();}); }}
This breaks your search into another function, and we are delaying only 500ms between killing one key and firing that search function. If you write another letter, then resets the 500ms timer with clearInterval ()
, so typing 20 entries will not trigger from this fast, only once you block half seconds The part that will fire will be that this
is correct when executing setTimeout ()
.
Comments
Post a Comment