Clear the cache for jquery ui autocomplete
Asked Answered
A

2

14

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?

Affirmative answered 23/5, 2012 at 18:51 Comment(1)
how does your code look like? afaik, autocomplete has no internal cache mechanism. you build your own.Sprout
S
24

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);
    });
}
Selfeffacing answered 23/5, 2012 at 18:55 Comment(0)
T
1

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.

Tasteful answered 13/12, 2018 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.