jquery keyboard pause catch -


am catching keyup events makes calls each keyup.

jquery('#search').keyup(function() {  }); 

but need when user continuously types characters , gave pass @ 5th character or in n'th character time want trigger ajax call. here can use timeout function catch event each keypress call timeout function again same thing happening

and if user again started typing after pause again have trigger event/ajax call after pause only.

here need abort previous events or ajax calls since again user started searching.

so used .abort(); function abort previous calls.

is there better way catch event @ after period of time in jquery. please advice me,

thanks in advance

var search = $('#search'),     search_delay = 100;    search.keyup(function() {     var request = search.data('request');      if(request) { // if request running - abort         request.abort();          search.data('request', null);     }      cleartimeout(search.data('timer')); // if timer running - stop      search.data('timer', settimeout(function(){         // add ajax call here or pass reference          // function handle ajax call         search.data('request', $.ajax(...));      }, search_delay);  }); 

you can use jq data api store references intrduced in jquery 1.5 jqxhr object able abort request , timer can stop timer cleartimeout


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -