I have the following jQuery code:
$('.button').click(function(e) {
e.preventDefault();
var id = $(this).attr('id');
var panel = $('#picpanel' + id);
var panelhtml = '<ol id="piclist' + id + '" class="piclist"></ol>';
panel.html(panelhtml);
panel.slideToggle(200);
$(this).toggleClass('active');
$.ajax({
type: 'GET',
url: 'index.php',
data: 'id=' + id + '&submit=getpicture',
cache: false,
success: function(html) {
$('#piclist' + id).append(html);
}
});
});
Basically, the pictures are read from database upon clicking a button. A panel showing all the pictures is also hidden before clicking the button. When I click the button, the panel is shown, and pictures are read and shown; there is no problem.
The problem is, when I click the button again, I want to hide the panel. It can be hidden, but it seems the AJAX runs again, which is of course unwanted. How to avoid that?