twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Unable to clear the remote cache #1351

Open HemantChavan opened 9 years ago

HemantChavan commented 9 years ago

I am using the latest typeahead library v0.11.1.

var engine = new Bloodhound({ datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.Name); }, queryTokenizer: Bloodhound.tokenizers.whitespace,

        remote: {
            cache: false,
            url: url + '?SearchText=%QUERY',
            wildcard: '%QUERY',
        }
    });

    engine.clearRemoteCache();
    engine.initialize(true);

i am unable to clear the remote cache response which i have received. I want to fetch the fresh response on every input click.

Can you please provide me some pointer to clear the previous response and create a new request on each input.

HemantChavan commented 9 years ago

Hi,

The above issue was present due to IE ajax call behavior. IE caches ajax call requests. Please see link for more clarification. http://stackoverflow.com/questions/20411043/autocomplete-off-ignored-in-ie I have fixed this issue of cache clear in IE by changing the Remote AJAX settings.

like below

var Remote = function() { "use strict"; function Remote(o) { this.url = o.url; this.prepare = o.prepare; this.transform = o.transform; this.transport = new Transport({ cache: o.cache, limiter: o.limiter, transport: o.transport }); } _.mixin(Remote.prototype, { _settings: function settings() { return { url: this.url, type: "GET", dataType: "json", cache: false /////////Added to clear cache in each ajax call. }; }, get: function get(query, cb) { var that = this, settings; if (!cb) { return; } query = query || ""; settings = this.prepare(query, this._settings()); return this.transport.get(settings, onResponse); function onResponse(err, resp) { err ? cb([]) : cb(that.transform(resp)); } }, cancelLastRequest: function cancelLastRequest() { this.transport.cancel(); } }); return Remote; }();