mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-25 14:17:45 +00:00
Added canUseCache: function option.
Check if this query can be autocompleted from cache, without ajax request. Usage (directory autocomplete, do ajaxs only if "/" has been typed): $(selector).autocomplete({ ... canUseCache: function(query) { return query.length == 0 || query[query.length - 1] != "/"; }, ... });
This commit is contained in:
parent
5db721d7b6
commit
3cb1c471df
@ -73,6 +73,7 @@
|
||||
tabDisabled: false,
|
||||
dataType: 'text',
|
||||
currentRequest: null,
|
||||
canUseCache: null,
|
||||
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
||||
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
||||
},
|
||||
@ -434,17 +435,23 @@
|
||||
if(this.currentRequest != null) {
|
||||
this.currentRequest.abort();
|
||||
}
|
||||
this.currentRequest = $.ajax({
|
||||
url: serviceUrl,
|
||||
data: options.ignoreParams ? null : options.params,
|
||||
type: options.type,
|
||||
dataType: options.dataType
|
||||
}).done(function (data) {
|
||||
that.processResponse(data, q);
|
||||
if ($.isFunction(options.canUseCache) && options.canUseCache(q) && that.cachedData) {
|
||||
that.processResponse(that.cachedData, q);
|
||||
options.onSearchComplete.call(that.element, q);
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
||||
});
|
||||
} else {
|
||||
this.currentRequest = $.ajax({
|
||||
url: serviceUrl,
|
||||
data: options.ignoreParams ? null : options.params,
|
||||
type: options.type,
|
||||
dataType: options.dataType
|
||||
}).done(function (data) {
|
||||
that.cachedData = data;
|
||||
that.processResponse(data, q);
|
||||
options.onSearchComplete.call(that.element, q);
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user