(^212) ❘ CHAPTER 7 AJAX
if (!$(this).next().children('ul').length)
{
var tree = $(this);
var file = (
$(this)
.prev()
.data('id') + '.html'
);
$.ajax({
beforeSend : function(event, request, options)
{
$('div#folderActivity').show();
},
success : function(response, status, request)
{
$('div#folderActivity').hide();
tree.attr('src', arrow)
.next()
.html(response)
.show();
},
error : function(request, status, error)
{
$('div#folderActivity').hide();
},
url : 'Example%207-8/' + file,
dataType : 'html'
});
}
else
{
$(this).next().toggle();
if ($(this).attr('src').indexOf('down') != -1)
{
arrow = 'tree/right.png';
}
$(this).attr('src', arrow);
}
}
);
}
);
The preceding example is functionally identical to the last two examples that you’ve seen in this
section. Just like those other two examples, you are requesting the contents of each folder with each
AJAX request, and you’re showing an activity indicator that appears while the AJAX request is
taking place and is hidden when it completes. Because the $.ajax() method works by calling that
method of the jQuery object directly, you have to change your approach from using the
http://www.it-ebooks.info
elliott
(Elliott)
#1