I'm using Ajax to delete images from my page. Ajax call works well when I delete the first image on the list, and it works when the second is also deleted and so on. However, when I try to delete from the middle, bottom or any image that's not first on the list the ajax request fails and instead the form is submitted and returns error. I don't know why I can't delete any other image except the first on the list. Please help me with a fix. My code is below:
JS
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function(){
$('#delform').on('submit', function(e){
e.preventDefault();
var wid = $('#wid').val();
$.ajax({
type: "POST",
url: 'delete-photo.php',
data: {wid: wid},
success: function(data){
alert("Image Deleted Successfully.");
location.reload();
}
});
return false;
});
});
</script>
FORM
<form id="delform">
<input type="hidden" name="wid" id="wid" value="<?php echo $wid; ?>">
<input type="submit" name="submit" class ="del-Pic top-50 bottom-0" value="Delete">
</form>