annotate jquery-ui/development-bundle/demos/autocomplete/remote-with-cache.html @ 0:b2e4605f20b2

beta version
author dwinter
date Thu, 30 Jun 2011 09:07:49 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
1 <!DOCTYPE html>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
2 <html lang="en">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
3 <head>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
4 <meta charset="utf-8">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
5 <title>jQuery UI Autocomplete - Remote with caching</title>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
7 <script src="../../jquery-1.5.1.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
8 <script src="../../ui/jquery.ui.core.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
9 <script src="../../ui/jquery.ui.widget.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
10 <script src="../../ui/jquery.ui.position.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
11 <script src="../../ui/jquery.ui.autocomplete.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
12 <link rel="stylesheet" href="../demos.css">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
13 <style>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
14 .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
15 </style>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
16 <script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
17 $(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
18 var cache = {},
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
19 lastXhr;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
20 $( "#birds" ).autocomplete({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
21 minLength: 2,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
22 source: function( request, response ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
23 var term = request.term;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
24 if ( term in cache ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
25 response( cache[ term ] );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
26 return;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
27 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
28
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
29 lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
30 cache[ term ] = data;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
31 if ( xhr === lastXhr ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
32 response( data );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
33 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
34 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
35 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
36 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
37 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
38 </script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
39 </head>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
40 <body>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
41
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
42 <div class="demo">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
43
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
44 <div class="ui-widget">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
45 <label for="birds">Birds: </label>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
46 <input id="birds" />
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
47 </div>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
48
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
49 </div><!-- End demo -->
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
50
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
51
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
52
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
53 <div class="demo-description">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
54 <p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.</p>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
55 <p>Similar to the remote datasource demo, though this adds some local caching to improve performance. The cache here saves just one query, and could be extended to cache multiple values, one for each term.</p>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
56 </div><!-- End demo-description -->
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
57
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
58 </body>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
59 </html>