jQuery 自动完成请求缓存问题

发布于 2024-09-14 19:50:40 字数 729 浏览 1 评论 0原文

我正在使用 已弃用的自动完成插件 (因为我使用的是旧版 jquery lib 1.3.2 )。

我的问题是自动完成插件尝试缓存请求。我正在使用服务器端 url 来返回结果。

考虑这个场景:

Keyword : Results
i : ikea, iphone, ipod, ipad, iphone 4
ip: iphone, ipod, ipad, iphone4
iph: iphone, iphone 4
ipho: iphone, iphone 4

...

你看到问题了,第一次得到 5 个结果 - 这是我在后端设置的限制,它只返回 5 个结果。下次,它不会发送请求,而是会优化在第一个请求中获得的结果集,依此类推。

如何使自动完成插件在每次输入更改时发送请求?

这是我的代码...

$("#query").autocomplete(
    "/getSuggestions/", {
        autoFill: true,
        selectFirst: false,
        cacheLength: 1
    });

我尝试将cacheLength设置为“1”,但这不起作用。

有人可以帮我一下吗?

I am using the deprecated autocomplete plugin (since I'm using the legacy jquery lib 1.3.2).

My problem is that the autocomplete plugin tries to cache the requests. I am using a server side url to return the results.

Consider this scenario:

Keyword : Results
i : ikea, iphone, ipod, ipad, iphone 4
ip: iphone, ipod, ipad, iphone4
iph: iphone, iphone 4
ipho: iphone, iphone 4

...

You see the problem, the first time it got 5 results - that's the limit I have set at backend, its returning 5 results only. The next time, it doesn't send a request, it refines the resultset it got in first request and so on.

How can I make the autocomplete plugin send a request everytime the input changes?

Here is my code...

$("#query").autocomplete(
    "/getSuggestions/", {
        autoFill: true,
        selectFirst: false,
        cacheLength: 1
    });

I tried setting the cacheLength to "1", but that doesn't work.

Can somebody help me out over here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隱形的亼 2024-09-21 19:50:40
$("#query").autocomplete(
    "/getSuggestions/", {
        autoFill: true,
        selectFirst: false,
        cacheLength: 0
    });

事实证明这是一个非常简单的解决方案 - 将cacheLength 设置为0 就可以了。

到目前为止,我正在参考 文档 中的解释...

后端查询结果数
存储在缓存中。 如果设置为 1
当前结果),不会缓存
发生。必须 >= 1。


无论如何我得到了想要的解决方案。

$("#query").autocomplete(
    "/getSuggestions/", {
        autoFill: true,
        selectFirst: false,
        cacheLength: 0
    });

It turned out to be quite a simple solution - setting the cacheLength to 0 does the trick.

I was referring the explanation in documentation till now...

The number of backend query results to
store in cache. If set to 1 (the
current result), no caching will
happen
. Must be >= 1.

Anyway I got the desired solution.

红ご颜醉 2024-09-21 19:50:40

您不需要禁用缓存,可以选择禁用子集匹配,例如

$("#query").autocomplete(
    url,
    {
        matchSubset: false
    }
)

You don't need to disable caching, there is option to disable subset matching e.g.

$("#query").autocomplete(
    url,
    {
        matchSubset: false
    }
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文