I have retrieved some rows from the database by ajax request and added to my HTML page. I want to delete a record using ajax but it doesn't work.
$(document).ready(() => {
$.getJSON("/admin/getMakes", data => {
$.each(data, (i, makes) => {
$("ul#makes").append(
'<li class="list-group-item">' +
makes.makeName +
' <a href="#",id="deleteMake",data-id=' +
makes._id +
'><i class="fa fa-trash" ></i></a>' +
"</li>"
);
});
});
$("#deleteMake").on("click", function(e) {
alert("clicked");
// var id = $(this).attr("data-id");
// $.ajax({
// type: "DELETE",
// url: "/admin/deletemake" + id,
// success: function(response) {
// $(this).hide();
// //window.location.href = "/admin/deletemake";
// },
// error: function(err) {
// console.log(err);
// }
// });
});
});
I have added an alert to check if it works but it doesn't work so the mistake isn't in the request.