jQuery stop previous search result from loading -


i made simple live search function filter results in table.

see below:

$( "#searchinput" ).keyup(function() {    if ($( "#searchinput" ).val() == ''){     //leeg     $( "#tabledatadiv" ).html('loading...');     $( "#tabledatadiv" ).load('tabledata.php');   }else{     //niet leeg     $( "#tabledatadiv" ).html('loading...');     $( "#tabledatadiv" ).load('tabledata.php?searchquery='+encodeuricomponent($( "#searchinput" ).val()));   }  }); 

the problem when user typing fast, , previous "string"my script searching has lot of results, result of previous search overwrites results of final one.

so, when searching "ax" gives 2 results, first tries (while typing) search "a" has 5000 results.

loading result ax takes less time loading results a, result need short time, , content of div overwritten result "a".

how prevent this? when user types in searchbox, should stop loading or displaying result of previous keystroke.

you should use autocomplete api of jquery-ui. gives lot of options (like delay, minlength, etc).

if need abort previous request can use like this.


Comments

Popular posts from this blog

rewrite asp to php based on asp query -

android - questions about switching from C2DM to GCM -

visual studio 2010 - Error on RDLC Expression -