Anecito Alima Santillan Anecito Alima Santillan - 1 year ago 90
Ajax Question

delete record from database without refreshing

I have an code where it is supposed to delete the data without refreshing. the delete process works but i have to refresh to to remove the data.
heres my code please help me


$(function () {
$(".trash").click(function () {
var del_id = $(this).attr("id");
var info = 'id=' + del_id;
if (confirm("Sure you want to delete this post? This cannot be undone later.")) {
type: "POST",
url: "delete.php", //URL to the delete php script
data: info,
success: function () {}
opacity: "hide"
}, "slow");
return false;

Here's my html:

<td style="padding-left: 23px">
<img class="photo" data-toggle="modal" data-target="#gallery<?php echo $photo; ?>" src="<?php echo $r1['photo']; ?>" />

<div class="hotel">
<button class="trash" id="<?php echo $r1['photo_id']; ?>" > <span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>

If I hover the button to the image the
button will appear and if I click it the image must be deleted. help me please.

Answer Source

You can give a data image id attr to parent tr,

<tr data-image-id="<?php echo $r1['photo_id']; ?>">

After successful delete process (in your ajax success function) you can run code below.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download