开发者

remove autocomplete from cache results

开发者 https://www.devze.com 2023-03-22 10:24 出处:网络
I\'ve the following problem. I used to have an input with auto-completion, I removed this just recently from the field (as it was no longer necassery).

I've the following problem. I used to have an input with auto-completion, I removed this just recently from the field (as it was no longer necassery).

The field is now: <input type="text" class="required text motivationname valid" maxlength="30" onblur="isDoubleMotivation(this.value);" value="" id="title" name="title"> nothing special right?

I've another auto-completion field which gets filled with information about cities.

var elements = $开发者_开发技巧('input.auto_plaatsnaam');
    elements.each(function() {
        $(this).autocomplete( {
            dataType: "json",
            source: "/common/ajax/citysearch.php",
            minLength: 1,
            cache: false,
            delay: 100
        });
    });

The problem is as follows: some users get the auto-complete on the first (title) input field. I'm thinking it's a cache problem as removing the cache solves the problem. Can I force with php or js to flush the cache before the field is loaded? Removing all caches is not really beneficial to the site so I'm hoping I just could remove the caching of these fields.


It seems an update of a more recent version of jquery ui has solved the problem. Thanks all!


A robust solution is to a add a parameter to your query url, containing the timestamp.

Example (not actually tested) :

var elements = $('input.auto_plaatsnaam');
elements.each(function() {
    $(this).autocomplete( {
        dataType: "json",
        source: function() { return "/common/ajax/citysearch.php?t="+new Date().getTime()},
        minLength: 1,
        cache: false,
        delay: 100
    });
});

This way, the url for the AJAX call is always different, so no cache is made by the browser.


Assuming that you keep your js in file 'myjs.js' you can modify corresponding script tag to this

<script src="/path/to/myjs.js?version=0.01"></script>
0

精彩评论

暂无评论...
验证码 换一张
取 消