refactor below code: // Show the file input when a picture is deleted…
- User
refactor below code: // Show the file input when a picture is deleted document.addEventListener('DOMContentLoaded', function () { const deleteIcons = document.querySelectorAll('.delete-icon'); const fileInputContainer = document.getElementById('fileInputContainer');
deleteIcons.forEach((deleteIcon) => { deleteIcon.addEventListener('click', function () { const pictureId = this.getAttribute('data-picture-id'); // Send an AJAX request to delete the picture (handle this on the server) try { const response = await fetch(
/admin/delete/picture/${pictureId}, { method: 'DELETE', headers: { 'X-CSRF-Token': '<%= csrfToken %>' } }); if (response.ok) { // Picture deleted successfully, show the file input fileInputContainer.style.display = 'block'; this.parentElement.remove(); // Remove the deleted picture } else { console.log('Failed to delete picture'); } } catch (error) { console.error('An error occurred while deleting the picture', error); } }); }); }); Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.