kkh
kkh

Reputation: 4869

Delete using ajax

I have a div in which its data is populated from the backend php. I am using codeigniter here. The div is something like this

if(isset($result))
{
echo '
  <div>
    <div>
     $result->value
    </div>
    <a>Delete</a>
  </div>
';
}

The delete is done using ajax. But how do I do a refresh of the div which is not supposed to show anything after the deletion?

Upvotes: 0

Views: 266

Answers (2)

Jai
Jai

Reputation: 74748

Do this in your ajax success function:

$(this).closest('div').slideUp().remove();

This way visually you would see a slideup and after sliding up this would get removed from the dom and this won't appear again if successfully removed from db.

Then if you refresh your page you won't see that div again.

Upvotes: 1

GGio
GGio

Reputation: 7653

having some kind of class identifier on delete is always a good way for future extensions/modifications.

<div>
    <div>
     $result->value
    </div>
    <a class="deleteme">Delete</a>
</div>

either case you can use this:

$(document).on('click', '.deleteme', function() {
   //your delete stuff 
   if (your delete was successful) {
     $(this).parent().fadeOut(500);
   }
});

Upvotes: 0

Related Questions