Prevent Posts While Typing In A Input
I have a input field as filter. At every keyup he calls a function to post the input.val() to display the result in a table, this works fine. but if i'm typing a name 'stackoverflo
Solution 1:
You can use the native Javascript functions clearTimeout and setTimeout to accomplish this.
$(document).ready(function(){
var filterTimeout = null;
$("#filter").keyup(function(){
if (filterTimeout != null)
window.clearTimeout(filterTimeout);
filterTimeout = window.setTimeout(function() { console.log('POST'); }, 3000);
});
});
Solution 2:
Check out the jQuery throttle / debounce plugin
It does exactly what you want
$('input').keyup($.debounce(3000, function() { /* Post comes here */ }));
Post a Comment for "Prevent Posts While Typing In A Input"