c# - How to make a ajax filter in jquery? -
i trying make filtering user search last name. right have on keypress of course many ajax requests rather have after few keys or that.
i return results table(i have partial view generates table info in it)
$(function () { $('#lastname').keypress(function () { $.post('actionmethod', { 'lastname': $(this).val() }, function (response) { $('#results').html(response); }); }); });
any ideas how should this. guess logic similar auto complete , know can set how many keystrokes before query db.
i think should use timeouts , delay execution of ajax call. if keypress occurs before execution reset timer...
$(function () { var timer; $('#lastname').keypress(function () { var _this = this; // need store variable since called out of context timeout cleartimeout(timer); timer = settimeout(function(){ $.post('actionmethod', { 'lastname': $(_this).val() }, function (response) { $('#results').html(response); }); }, 500); // delay 500 milliseconds }); });
Comments
Post a Comment