You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 436B

12345678910111213141516
  1. document.querySelectorAll('[data-delete]').forEach((el) => {
  2. el.addEventListener('click', (e) => {
  3. if (confirm('Are you sure? This cannot be undone.')) {
  4. let postId = e.target.dataset.delete;
  5. fetch(`/posts/${postId}`, {
  6. method: 'DELETE',
  7. }).then((r) => {
  8. r.json().then((data) => {
  9. if (data.success) {
  10. window.location = '/';
  11. }
  12. });
  13. });
  14. }
  15. });
  16. });