I want to trigger an event just after I stop typing (not while typing) characters in my input textbox.
I've tried with:
$('input#username').keypress(function() {
    var _this = $(this); // copy of this object for further usage
    setTimeout(function() {
        $.post('/ajax/fetch', {
            type: 'username',
            value: _this.val()
        }, function(data) {
            if(!data.success) {
                // continue working
            } else {
                // throw an error
            }
        }, 'json');
    }, 3000);
});
But this example produces a timeout for every typed character and I get about 20 AJAX requests if I type-in 20 characters.
On this fiddle I demonstrate the same problem with a simple alert instead of an AJAX.
Is there a solution for this or I'm just using a bad approach for this?
 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    