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>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
var cache = {};
|
var cache = {},
|
||||||
|
lastXhr;
|
||||||
$( "#birds" ).autocomplete({
|
$( "#birds" ).autocomplete({
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
source: function(request, response) {
|
source: function(request, response) {
|
||||||
if ( request.term in cache ) {
|
var term = request.term;
|
||||||
response( cache[ request.term ] );
|
if ( term in cache ) {
|
||||||
|
response( cache[ term ] );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
|
||||||
url: "search.php",
|
cache[ term ] = data;
|
||||||
dataType: "json",
|
if ( xhr === lastXhr ) {
|
||||||
data: request,
|
|
||||||
success: function( data ) {
|
|
||||||
cache[ request.term ] = data;
|
|
||||||
response( data );
|
response( data );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user