Ross
Ross

Reputation: 46987

jQuery callback not being called

I'm using the .post AJAX method of jQuery:

// completion toggling
$('.item input').click(function() {
    $.post('complete.php', {item: this.id}, function() {
        $(this).parent().fadeOut('slow');
    });
});

What am I doing wrong here? The AJAX works as the record is updated but the callback event never happens. No errors in Firebug either.

Upvotes: 3

Views: 3042

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062660

I wonder if it isn't a different "this" at that point. Try using a capture:

$('.item input').click(function() {
    var tmp = this;
    $.post('complete.php', {item: this.id}, function() {
        $(tmp).parent().fadeOut('slow');
    });
});

Upvotes: 3

Related Questions