let axios = require("axios"); //even delegation $("body").on("click", ".delete-projects", function() { let id = $(this).data("id"); // axios will send a delete request with this URL axios .delete("/projects/" + id) .then(function() { window.location.reload(); }) .catch(function(error) { console.log(error); }); });