jQuery UI autocomplete results returned out of order
I am running into an issue where the Ajax requests for an autocomplete search are returning out of order (i.e. some requests are cached and returning before earlier requests). The开发者_运维技巧 autocomplete results are showing the last result returned, not the result for the last search term typed.
Reading autocomplete change logs and the source code, it looks like attempts to cancel the older XHR requests are in there, but they don't appear to be working.
I am using jQuery 1.5.1 and jQuery UI 1.8.10 along with jquery.ui.autocomplete.html.js
Is autocomplete supposed to handle this situation? Or am I supposted to manage and abort previous Ajax requests in my application code?
You can have some flag controlling whether you are alreading making requests and abort old ones, like:
var running = undefined;
//on your autocomplete data source callback:
if (running) running.abort(); //abort previous requests
running = $.ajax({
... your ajax magic here
});
精彩评论