Autocomplete: Fixed handling of race conditions when using jQuery 1.3.2. Fixes #6904 - Autocomplete: Race condition handling means.

This commit is contained in:
Scott González 2011-01-27 14:49:59 -05:00
parent 7a6dd71f8c
commit a1ab9678e9

View File

@ -15,6 +15,9 @@
*/ */
(function( $, undefined ) { (function( $, undefined ) {
// used to prevent race conditions with remote data sources
var requestIndex = 0;
$.widget( "ui.autocomplete", { $.widget( "ui.autocomplete", {
defaultElement: "<input>", defaultElement: "<input>",
options: { options: {
@ -257,17 +260,16 @@ $.widget( "ui.autocomplete", {
url: url, url: url,
data: request, data: request,
dataType: "json", dataType: "json",
success: function( data, status, xhr ) { autocompleteRequest: ++requestIndex,
if ( xhr === self.xhr ) { success: function( data, status ) {
if ( this.autocompleteRequest === requestIndex ) {
response( data ); response( data );
} }
self.xhr = null;
}, },
error: function( xhr ) { error: function() {
if ( xhr === self.xhr ) { if ( this.autocompleteRequest === requestIndex ) {
response( [] ); response( [] );
} }
self.xhr = null;
} }
}); });
}; };