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.
  • Loading branch information
scottgonzalez committed Jan 27, 2011
1 parent 7a6dd71 commit a1ab967
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -15,6 +15,9 @@
*/
(function( $, undefined ) {

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

$.widget( "ui.autocomplete", {
defaultElement: "<input>",
options: {
Expand Down Expand Up @@ -257,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;
}
});
};
Expand Down

1 comment on commit a1ab967

@scottgonzalez
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a reduced test case showing the problem.

Please sign in to comment.