diff options
author | Scott González <scott.gonzalez@gmail.com> | 2010-04-23 12:19:06 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2010-04-23 12:19:06 -0400 |
commit | e087e7dee07555f7b78e108dc414959998628ec7 (patch) | |
tree | 512ade389ccd281e8af525ae647092268acf2ec4 /demos/autocomplete/remote-with-cache.html | |
parent | 02c32959d9761e56be9471f87eff0554b4f4a61d (diff) | |
download | jquery-ui-e087e7dee07555f7b78e108dc414959998628ec7.tar.gz jquery-ui-e087e7dee07555f7b78e108dc414959998628ec7.zip |
Autocomplete: Changed cache demo to cache all results.
Fixes #5398 - Remote-with-cache demo does not break if (cache.term == request.term) but executes another request.
Diffstat (limited to 'demos/autocomplete/remote-with-cache.html')
-rw-r--r-- | demos/autocomplete/remote-with-cache.html | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/demos/autocomplete/remote-with-cache.html b/demos/autocomplete/remote-with-cache.html index a00c741e4..b7f688175 100644 --- a/demos/autocomplete/remote-with-cache.html +++ b/demos/autocomplete/remote-with-cache.html @@ -12,36 +12,24 @@ <link type="text/css" href="../demos.css" rel="stylesheet" /> <script type="text/javascript"> $(function() { - function log(message) { - $("<div/>").text(message).prependTo("#log"); - $("#log").attr("scrollTop", 0); - } - var cache = {}; - $("#birds").autocomplete({ + $( "#birds" ).autocomplete({ + minLength: 2, source: function(request, response) { - if (cache.term == request.term && cache.content) { - response(cache.content); - return; - } - if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) { - response($.ui.autocomplete.filter(cache.content, request.term)); + if ( request.term in cache ) { + response( cache[ request.term ] ); return; } + $.ajax({ url: "search.php", dataType: "json", data: request, - success: function(data) { - cache.term = request.term; - cache.content = data; - response(data); + success: function( data ) { + cache[ request.term ] = data; + response( data ); } }); - }, - minLength: 2, - select: function(event, ui) { - log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value); } }); }); @@ -56,11 +44,6 @@ <input id="birds" /> </div> -<div class="ui-widget" style="margin-top:2em; font-family:Arial"> - Result: - <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> -</div> - </div><!-- End demo --> <div class="demo-description"> |