Autocomplete: Abort existing ajax requests when running new searches.

This commit is contained in:
Scott González 2010-08-24 21:41:34 -04:00
parent f115b48d2b
commit da2be6a2af

View File

@ -221,10 +221,14 @@ $.widget( "ui.autocomplete", {
} else if ( typeof this.options.source === "string" ) { } else if ( typeof this.options.source === "string" ) {
url = this.options.source; url = this.options.source;
this.source = function( request, response ) { this.source = function( request, response ) {
if (self.xhr) {
self.xhr.abort();
}
self.xhr = $.getJSON( url, request, function( data, status, xhr ) { self.xhr = $.getJSON( url, request, function( data, status, xhr ) {
if ( xhr === self.xhr ) { if ( xhr === self.xhr ) {
response.apply( this, arguments ); response( data );
} }
self.xhr = null;
}); });
}; };
} else { } else {