On Jan 6, 4:42 am, Lone Wolf <khura...@gmail.com> wrote:
> $(document).ready(function(){
>         $('table.small td img.delete').click(function(){
>           $.get('ajax/update-callback.php', {doaction: 'remove', callbackid: $
> (this).attr('id')},
>                 function(data){
>                         alert($(this).attr('id'));
>                         $(this).remove();
>           });
>         });
>
> });
>
> update-callback.php is called and the function is performed by php.
> However, in the callback function of the jQuery, $(this) is not
> available as alerting its attr('id') gives undefined which it happily
> added in the GET of the update-callback.php. Can you tell me what I
> could be doing wrong.

The "this" reference in your callback function does not refer back to
the "this" in your outer function. [1]

You need to save a reference to it to use in the callback.

This is untested, but might do it:

    $(document).ready(function(){
        $('table.small td img.delete').click(function(){
            var deleteImg = $(this);
            $.get('ajax/update-callback.php', {/* ... */},
                function(data){
                    alert(deleteImg.attr('id'));
                    deleteImg.remove();
                }
            );
        });
    });

Cheers,

  -- Scott
____________________
[1] According to the docs, "this" refers to the options for your ajax
request

Reply via email to