Clear the cache for jquery ui autocomplete

安稳与你 提交于 2019-11-30 22:39:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!