// Generic Ajax Modal Load Script // /*Trigger Button using data-ajax attributes --> */ $(document).on('click', '.ajax-trigger', function (e) { e.preventDefault(); // Get the URL and ID from the element's data attributes var $trigger = $(this); var ajaxUrl = $trigger.data('ajax-url'); var ajaxId = $trigger.data('ajax-id'); // Make the AJAX call to fetch modal content $.ajax({ url: ajaxUrl, method: 'GET', data: { id: ajaxId }, dataType: 'json', success: function (response) { if (response.error) { alert(response.error); return; } // Create a unique modal ID (you can enhance this as needed) var modalId = 'dynamicAjaxModal'; // Build the modal HTML using the returned title and content var modalHtml = '
'; // Append the modal to the body and show it $('body').append(modalHtml); $('#' + modalId).modal('show'); // Remove the modal from the DOM once it's hidden $('#' + modalId).on('hidden.bs.modal', function () { $(this).remove(); }); }, error: function () { alert('Error loading modal content.'); } }); });