Autocomplete cache demo: Let the widget handle request synchronization. Fixes #8616 - Remote autocomplete example can leave pending request tracking out of sync.

This commit is contained in:
Scott González 2012-10-02 10:21:52 -04:00
parent 2c50b1b8b5
commit 5405a821b9

View File

@ -18,8 +18,7 @@
</style> </style>
<script> <script>
$(function() { $(function() {
var cache = {}, var cache = {};
lastXhr;
$( "#birds" ).autocomplete({ $( "#birds" ).autocomplete({
minLength: 2, minLength: 2,
source: function( request, response ) { source: function( request, response ) {
@ -29,11 +28,9 @@
return; return;
} }
lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) { $.getJSON( "search.php", request, function( data, status, xhr ) {
cache[ term ] = data; cache[ term ] = data;
if ( xhr === lastXhr ) { response( data );
response( data );
}
}); });
} }
}); });