]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Fixed handling of race conditions when using jQuery 1.3.2. Fixes #6904...
authorScott González <scott.gonzalez@gmail.com>
Thu, 27 Jan 2011 19:49:59 +0000 (14:49 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 27 Jan 2011 19:50:40 +0000 (14:50 -0500)
(cherry picked from commit a1ab9678e9bba6b20989104040bc31b782094335)

ui/jquery.ui.autocomplete.js

index 2ab3bfda999ce43b2c4f3d90500c12d1c19d8c61..a497b72fda9c0b3b6ddd49c82f357a4f97d855bc 100644 (file)
@@ -14,6 +14,9 @@
  */
 (function( $, undefined ) {
 
+// used to prevent race conditions with remote data sources
+var requestIndex = 0;
+
 $.widget( "ui.autocomplete", {
        options: {
                appendTo: "body",
@@ -256,17 +259,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;
                                        }
                                });
                        };