diff options
author | Scott González <scott.gonzalez@gmail.com> | 2010-08-27 12:47:19 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2010-08-27 12:47:19 -0400 |
commit | 4400632f539eae3fdf24fed134a8749fe8300b53 (patch) | |
tree | 2f8595284270f96df4adda87be45e8a3b24f1520 /demos | |
parent | 16e93d5189a5aed10df23e85b5d40b14d126eede (diff) | |
download | jquery-ui-4400632f539eae3fdf24fed134a8749fe8300b53.tar.gz jquery-ui-4400632f539eae3fdf24fed134a8749fe8300b53.zip |
Autocomplete: Improved cache demo.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/autocomplete/remote-with-cache.html | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/demos/autocomplete/remote-with-cache.html b/demos/autocomplete/remote-with-cache.html index bd261f44e..77741fbe9 100644 --- a/demos/autocomplete/remote-with-cache.html +++ b/demos/autocomplete/remote-with-cache.html @@ -15,21 +15,20 @@ </style> <script type="text/javascript"> $(function() { - var cache = {}; + var cache = {}, + lastXhr; $( "#birds" ).autocomplete({ minLength: 2, source: function(request, response) { - if ( request.term in cache ) { - response( cache[ request.term ] ); + var term = request.term; + if ( term in cache ) { + response( cache[ term ] ); return; } - - $.ajax({ - url: "search.php", - dataType: "json", - data: request, - success: function( data ) { - cache[ request.term ] = data; + + lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) { + cache[ term ] = data; + if ( xhr === lastXhr ) { response( data ); } }); |