I am trying to achieve an Ajax search/autocomplete as user types in. Here is my code:
$('#productSearch').live('keyup',function(){
var searchterm = encodeURIComponent($('#productSearch').val());
$('.ajax-search-results').load('/ajax/search.php?type=product&s=' + searchterm);
});
The problem is that results are not consistent with the input value, I have no idea why, but when I type too fast (too fast for handling the .load() maybe?) the results at end are not consistent (not what I expect) if i type in slowly, it works perfectly.
Can someone tell me how can I come over this situation?
- I thought about disabling function until the load is done, but that would mean also that i will lose what the user has typed until the operation is done?