JQuery parent () hide () in the ajax response

advertisements

I want to be able to delete a user from a table then hide the div which shows them.

A user clicks on a button with class .buddy_delete which contains the info to pass to the php file which deletes them.

I have the following which works ok, but I need the $(this).parent().hide(); in the AJAX response instead of before the AJAX in case of any error, is this possible?

$('.buddy_delete').on('click', function(e) {
        e.preventDefault();
        var sei = $(this).attr('sei');
        var sui = $(this).attr('sui');
        $(this).parent().hide(); // ok here
        $.ajax({
            type: "POST",
            url: '/ajax/actions/remove_user_from_list.php?sei=' + sei + '&sui=' + sui,
            success: function (data) {
                if(data==='ok'){
                    // $(this).parent().hide(); // doesn't work here, nothing happens
                } else {
                    $('#errorBoxEvent').html('Houston, we have a problem!');
                }
            }
        }); // End .ajax function
    });


Set option context of ajax method:

$.ajax({
   context: this,
   //...
});