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

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -