Reputation: 357
I need to check if user is typing or not before i send an ajax request so my server is not hammered with every stroke, can someone guide me on how to do this?
Upvotes: 0
Views: 158
Reputation: 318498
What you are looking for is debouncing/throttling. Underscore.js
has useful functions for it.
$('#field').on('keyup change', _.debounce(function() {
// your ajax call
}), 2000);
This code would wait 2s after the last change before running your function.
Upvotes: 2