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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -