I'm trying to build a simple autocomplete list:
DOM:
<input id="example"/>
<div id="results"></div>
Javascript:
$('#example').keyup(function(e) {
$('#results').empty();
$.getJSON('Search?input=' + $('#example').val(), function(response) {
// This attaches the results to the results div
updateAutocomplete(response);
});
});
This works, except as the user is typing, I might receive the callbacks in different order. Is there anyway around this? I thought about attaching a timestamp to the results and doing a quick comparison (that way if an earlier response comes later, it'll get rejected). This must be a common problem, what's the best way around this?