PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php // Delete button if (event.type === 'class') { tooltipContent += '<button class="link-dark delete-button" data-event-type="class" data-event-id="' + event.class_id + '"><i class="fa-solid fa-trash fs-5"></i>Delete</button>'; } else if (event.type === 'event') { tooltipContent += '<button class="link-dark delete-button" data-event-type="event" data-event-id="' + event.event_id + '"><i class="fa-solid fa-trash fs-5"></i>Delete</button>'; } // Use event delegation for dynamically added buttons $(document).on('click', '.delete-button', function (event) { event.preventDefault(); // Retrieve the event type and ID from the data attributes var eventType = $(this).data('event-type'); var eventId = $(this).data('event-id'); console.log(eventId); // Perform the deletion logic based on the event type and ID if (eventType === 'class') { // Send an AJAX request to delete the class using admin_deleteClass.php $.ajax({ url: 'admin_deleteClass.php', type: 'POST', data: { id: eventId }, success: function (response) { // Handle the success response, e.g., show a success message or update the UI console.log('Class deleted successfully'); // Remove the event from the calendar $('#calendar').fullCalendar('removeEvents', eventId); // Show the success message showMessage('Class deleted successfully'); }, error: function (xhr, status, error) { // Handle the error response, e.g., show an error message console.error('Error deleting class:', error); // Show an error message showMessage('Error deleting class', 'error'); } }); } else if (eventType === 'event') { // Send an AJAX request to delete the event using admin_deleteEvent.php $.ajax({ url: 'admin_deleteEvent.php', type: 'POST', data: { id: eventId }, success: function (response) { // Handle the success response, e.g., show a success message or update the UI console.log('Event deleted successfully'); // Remove the event from the calendar $('#calendar').fullCalendar('removeEvents', eventId); // Show the success message showMessage('Event deleted successfully'); }, error: function (xhr, status, error) { // Handle the error response, e.g., show an error message console.error('Error deleting event:', error); // Show an error message showMessage('Error deleting event', 'error'); } }); } });
Show:  
Copy Clear