Skip to content

Commit a1ab967

Browse files
committed
Autocomplete: Fixed handling of race conditions when using jQuery 1.3.2. Fixes #6904 - Autocomplete: Race condition handling means.
1 parent 7a6dd71 commit a1ab967

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
(function( $, undefined ) {
1717

18+
// used to prevent race conditions with remote data sources
19+
var requestIndex = 0;
20+
1821
$.widget( "ui.autocomplete", {
1922
defaultElement: "<input>",
2023
options: {
@@ -257,17 +260,16 @@ $.widget( "ui.autocomplete", {
257260
url: url,
258261
data: request,
259262
dataType: "json",
260-
success: function( data, status, xhr ) {
261-
if ( xhr === self.xhr ) {
263+
autocompleteRequest: ++requestIndex,
264+
success: function( data, status ) {
265+
if ( this.autocompleteRequest === requestIndex ) {
262266
response( data );
263267
}
264-
self.xhr = null;
265268
},
266-
error: function( xhr ) {
267-
if ( xhr === self.xhr ) {
269+
error: function() {
270+
if ( this.autocompleteRequest === requestIndex ) {
268271
response( [] );
269272
}
270-
self.xhr = null;
271273
}
272274
});
273275
};

0 commit comments

Comments
 (0)