问题
I think I have read every stackoverflow and google result available on this issue and they all seem to refer to the first jquery autocomplete plugin and not the current jquery ui autocomplete.
What is the method for forcing the autocomplete results to update from the data source instead of the cached list?
回答1:
The jquery ui autocomplete does not do any caching. The caching is happening at the browser level. To prevent it from happening, use $.ajaxSetup
.
$.ajaxSetup({ cache: false });
You could also instead supply a function to the source option that does the ajax request for you with cache: false
if you don't want to disable caching globally.
source: function(request, response) {
$.ajax({
url: "url.php",
dataType: "json",
cache: false,
type: "get",
data: { term: request.term }
}).done(function(data) {
response(data);
});
}
回答2:
You can also add a random cache busting parameter to the source url that jQuery UI uses. jQuery UI is smart enough to handle appending the term parameter if there's already a cache busting parameter there.
来源:https://stackoverflow.com/questions/10726089/clear-the-cache-for-jquery-ui-autocomplete