$(function() {
// Handle link click event
$('#blog').on('click', '.item-link', function(e) {
e.preventDefault();
var url = $(this).data('url');
var modal = $('#test-modal');
var modalBody = modal.find('.modal-body');
// If content is already loaded, display it in the modal
if ($(this).data('loaded')) {
modalBody.html($(this).data('loaded-content'));
} else {
// Load content with AJAX and display it in the modal
modalBody.load(url, function(response, status, xhr) {
if (status == "error") {
modalBody.html('
Error loading content.
');
} else {
$(this).data('loaded', true);
$(this).data('loaded-content', response);
}
});
}
// Open the modal
modal.modal('show');
});
});