Skip to content
Permalink
Browse files

Autocomplete: Improved cache demo.

  • Loading branch information
scottgonzalez committed Aug 27, 2010
1 parent 16e93d5 commit 4400632f539eae3fdf24fed134a8749fe8300b53
Showing with 9 additions and 10 deletions.
  1. +9 −10 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 );
}
});

0 comments on commit 4400632

Please sign in to comment.
You can’t perform that action at this time.