Skip to content

Commit

Permalink
Autocomplete cache demo: Let the widget handle request synchronizatio…
Browse files Browse the repository at this point in the history
…n. Fixes #8616 - Remote autocomplete example can leave pending request tracking out of sync.
  • Loading branch information
scottgonzalez committed Oct 2, 2012
1 parent 2c50b1b commit 5405a82
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions demos/autocomplete/remote-with-cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
</style>
<script>
$(function() {
var cache = {},
lastXhr;
var cache = {};
$( "#birds" ).autocomplete({
minLength: 2,
source: function( request, response ) {
Expand All @@ -29,11 +28,9 @@
return;
}

lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
$.getJSON( "search.php", request, function( data, status, xhr ) {
cache[ term ] = data;
if ( xhr === lastXhr ) {
response( data );
}
response( data );
});
}
});
Expand Down

0 comments on commit 5405a82

Please sign in to comment.