【问题标题】:typeaheadjs: How to call server without using cached datatypeaheadjs:如何在不使用缓存数据的情况下调用服务器
【发布时间】:2013-12-11 11:19:03
【问题描述】:

我正在使用 typeaheadjs 并使用远程获取数据。当我输入“A”时,它会获取以“A”开头的数据,但下次我删除并重新输入“A”时,它会显示缓存中的数据。但是我每次都需要调用服务器而不重用之前的响应。

这是我的代码

    $('#demo').typeahead({
    remote: {
        url: '/Home/GetSuggestions?query=%QUERY&url=%URL',
        replace: function (url, query) {
            return url.replace('%QUERY', query).replace('%URL', 'http://www.example.com');
        },
    },
    minLength: 1,
    limit: 10,
    cache: false,
    valueKey: 'Key'
}).bind('typeahead:selected', function (obj, datum) {
    $.ajax({
        url: '/Home/UpdateTags/',
        type: 'POST',
        data: JSON.stringify(some_data),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            $('#demo').typeahead('setQuery', '');
        }
    });
});

我有了从here 添加 minLength 的想法。我错过了什么吗? 急切地等待帮助。

【问题讨论】:

    标签: javascript typeahead typeahead.js


    【解决方案1】:

    尝试在遥控器中移动缓存布尔值,这应该可以解决问题

    remote: {
        url: '/Home/GetSuggestions?query=%QUERY&url=%URL',
        replace: function (url, query) {
            return url.replace('%QUERY', query).replace('%URL', 'http://www.example.com');
        },
        cache: false
    },
    

    【讨论】:

      【解决方案2】:

      如果不查看代码库,一个老技巧可能会有所帮助:添加缓存破坏器。在您的 replace 函数中添加一个 _=randomdigits ,这将使 url 每次都唯一,如果缓存是按 url 完成的,则会阻止缓存。

      【讨论】:

        猜你喜欢
        • 2015-10-17
        • 1970-01-01
        • 2018-09-09
        • 2018-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-11
        • 1970-01-01
        相关资源
        最近更新 更多