jQuery autocomplete request caching problem

心已入冬 提交于 2020-01-24 00:33:11

问题


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?


回答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.




回答2:


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

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


来源:https://stackoverflow.com/questions/3518368/jquery-autocomplete-request-caching-problem

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