Skip to content

Commit 6b9b513

Browse files
committed
Autocomplete: Fixed handling of race conditions when using jQuery 1.3.2. Fixes #6904 - Autocomplete: Race condition handling means.
(cherry picked from commit a1ab967)
1 parent e117422 commit 6b9b513

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ui/jquery.ui.autocomplete.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
(function( $, undefined ) {
1616

17+
// used to prevent race conditions with remote data sources
18+
var requestIndex = 0;
19+
1720
$.widget( "ui.autocomplete", {
1821
options: {
1922
appendTo: "body",
@@ -256,17 +259,16 @@ $.widget( "ui.autocomplete", {
256259
url: url,
257260
data: request,
258261
dataType: "json",
259-
success: function( data, status, xhr ) {
260-
if ( xhr === self.xhr ) {
262+
autocompleteRequest: ++requestIndex,
263+
success: function( data, status ) {
264+
if ( this.autocompleteRequest === requestIndex ) {
261265
response( data );
262266
}
263-
self.xhr = null;
264267
},
265-
error: function( xhr ) {
266-
if ( xhr === self.xhr ) {
268+
error: function() {
269+
if ( this.autocompleteRequest === requestIndex ) {
267270
response( [] );
268271
}
269-
self.xhr = null;
270272
}
271273
});
272274
};

0 commit comments

Comments
 (0)