简体   繁体   中英

jQuery autocomplete request caching problem

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?

$("#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.

You don't need to disable caching, there is option to disable subset matching eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM