source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8.15/demos/autocomplete/remote-with-cache.html@ 24421

Last change on this file since 24421 was 24421, checked in by sjm84, 13 years ago

Adding a new version of jquery

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>jQuery UI Autocomplete - Remote with caching</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.6.2.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.position.js"></script>
11 <script src="../../ui/jquery.ui.autocomplete.js"></script>
12 <link rel="stylesheet" href="../demos.css">
13 <style>
14 .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
15 </style>
16 <script>
17 $(function() {
18 var cache = {},
19 lastXhr;
20 $( "#birds" ).autocomplete({
21 minLength: 2,
22 source: function( request, response ) {
23 var term = request.term;
24 if ( term in cache ) {
25 response( cache[ term ] );
26 return;
27 }
28
29 lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
30 cache[ term ] = data;
31 if ( xhr === lastXhr ) {
32 response( data );
33 }
34 });
35 }
36 });
37 });
38 </script>
39</head>
40<body>
41
42<div class="demo">
43
44<div class="ui-widget">
45 <label for="birds">Birds: </label>
46 <input id="birds" />
47</div>
48
49</div><!-- End demo -->
50
51
52
53<div class="demo-description">
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>
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>
56</div><!-- End demo-description -->
57
58</body>
59</html>
Note: See TracBrowser for help on using the repository browser.