I have a bootstrap modal I use for a deletion confirmation. After I submit a entry delete it will not work again until I reload the page. I am using javascript to watch for button click. The id attribute is passed to another function and submitted via ajax. The data-id attribute it not updated and still has the old button data-id.
I am not sure how to make the id attribute reset without reloading the page. Any help is appreciated. Sorry new to coding.
Here is the Button Code:
<button type="button" data-toggle="modal" data-target="#confirm_delete_modal" name="delete_btn" id="' + clockData.id + '" class="btn btn-xs btn-danger btn_delete"></button>
Here is the JS:
//Trigger Delete Confirmation Modal
$(document).on('click', '.btn_delete', function () {
var id = $(this).attr('id');
$('#delete_confirm').attr('id', id); //set the data attribute on the modal button
});
// Trigger Ajax delete function
$('#delete_confirm').click(function(){
var id = $(this).attr('id');
$.ajax({
url: "/clock/delete",
method: "POST",
data: {id: id},
success: function (data) {
$('#confirm_delete_modal').modal('hide');
search_data();
}
})
});