diff options
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 1342f7648..594d59530 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -15,7 +15,11 @@ */ (function( $, undefined ) { +// used to prevent race conditions with remote data sources +var requestIndex = 0; + $.widget( "ui.autocomplete", { + defaultElement: "<input>", options: { appendTo: "body", delay: 300, @@ -256,17 +260,16 @@ $.widget( "ui.autocomplete", { url: url, data: request, dataType: "json", - success: function( data, status, xhr ) { - if ( xhr === self.xhr ) { + autocompleteRequest: ++requestIndex, + success: function( data, status ) { + if ( this.autocompleteRequest === requestIndex ) { response( data ); } - self.xhr = null; }, - error: function( xhr ) { - if ( xhr === self.xhr ) { + error: function() { + if ( this.autocompleteRequest === requestIndex ) { response( [] ); } - self.xhr = null; } }); }; |