开发者

jQuery autocomplete request caching problem

开发者 https://www.devze.com 2023-01-11 23:46 出处:网络
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 r

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,
        selectFir开发者_如何学JAVAst: 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 e.g.

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

精彩评论

暂无评论...
验证码 换一张
取 消