Quote:
it's just refreshing but not deleting
That is a basic problem with jQuery and other JavaScript event handlers on the page. When you press a button, a JavaScript event is triggered that you attach to it, but that does not prevent the browser to perform the default action associated with the element.
For a
button
or
input[type='submit']
, the browser will post the content to the server and reload the page. In normal cases, a page is refreshed unless there is an action attribute applied to the form (if the element is within a
form
).
An easy way to handle this is to add a
event.preventDefault()
to the handler, which prevents the browser from "refreshing" the page. So your JavaScript code should be like:
$(document).ready(function(){
$(".delete_link").on('click', function(){
event.preventDefault();
var id = $(this).attr("rel");
var delete_url = "darb.php?delete="+ id;
$(".modal_delete_link").attr("href", delete_url);
$("#myModal").modal('show');
});
});
Now your code would run and show the modal—your modal will take it from here as the browser will not reload the page.
Read more about
event.preventDefault
here[
^].