Ajax Delete Function

Posted 3 years ago by jbowman99

I have a Notifications Panel each with a check button. the check button hits an ajax call

function markRead(id)
{
    $.ajax({
        type: "GET",
        url: "/notification/" + id,
        success: function (data) {
            console.log('deleted');
        }
    });

}

which triggers a controller method to change a pivot variable to read, the view loops over the pivot table and checks for the read variable and shows or doesn't show notifications based on that variable.

Currently the button does its job but the notification stays on the screen until the page is refreshed. I would like to change it to something along these lines:



$(document).ready(function() {
    $('.delete').click(function () {
        $('.notification-msg').fadeIn();
        var commentContainer = $(this).parent();
        var id = $(this).attr("id");
        var string = 'id=' + id;

        $.ajax({
            type: "GET",
            url: "/notification/" + id,
            data: string,
            cache: false,
            success: function () {
                commentContainer.slideUp('fast', function () {
                    $(this).remove();
                });
                $('.notification-msg').fadeOut();
            }

        });

        return false;
    });
});

but it just doesn't seem to want to hit the controller method or fade out..

any suggestions...

Thanks,

Jon

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.