views:

785

answers:

1

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.

+3  A: 

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');
    });
});
Marc Gravell
It is scoped by the braces - it won't conflict with other "tmp"s that are scoped in a similar way.
Marc Gravell
Oops! Somehow I deleted the OP's comment - it was "that works, need to check the scope" (or something similar)
Marc Gravell
That's correct 'this' in an AJAX call back is usually scoped to the XMLHttpRequest rather than a particular element.
sighohwell