mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Autocomplete: Improved cache demo.
This commit is contained in:
parent
16e93d5189
commit
4400632f53
@ -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 );
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user