Skip to content

Commit

Permalink
Autocomplete: Fixed handling of race conditions when using jQuery 1.3…
Browse files Browse the repository at this point in the history
….2. Fixes #6904 - Autocomplete: Race condition handling means.

(cherry picked from commit a1ab967)
  • Loading branch information
scottgonzalez committed Jan 27, 2011
1 parent e117422 commit 6b9b513
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -14,6 +14,9 @@
*/
(function( $, undefined ) {

// used to prevent race conditions with remote data sources
var requestIndex = 0;

$.widget( "ui.autocomplete", {
options: {
appendTo: "body",
Expand Down Expand Up @@ -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( [] );

This comment has been minimized.

Copy link
@meotimdihia

meotimdihia Mar 4, 2011

test

This comment has been minimized.

Copy link
@RedWolves

RedWolves Mar 4, 2011

Member

Please use QUnit for tests

}
self.xhr = null;
}
});
};
Expand Down

0 comments on commit 6b9b513

Please sign in to comment.