I am trying to make a filtering where a user would search by last name. Right now I have it on keypress but of course this does too many ajax requests so I would rather have it after a few keys or something like that.
I am return all the results as a table(I have a partial view that generates a table with the info in it)
$(function ()
{
$('#LastName').keypress(function ()
{
$.post('ActionMethod', { 'lastName': $(this).val() }, function (response)
{
$('#results').html(response);
});
});
});
Any ideas how I should do this. I guess the logic would be similar to a auto complete and I know they can set like how many keystrokes before you query db.
I think you should just use timeouts and delay the execution of the ajax call. If a keypress occurs before the execution then reset the timer…