The problem is that the ajax success function runs asynchronously. In
it, you refer to the variable id. So, when that function runs, it uses
the latest value of id, not the value of id when the click event
happened. Another way of handling the situation is to have your
deleteprivatemessage return data (json is easy) that contains the id

On Jan 25, 2:56 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have the following problem. I have a page with several links with
> class "deletepm", and when I click on the links in a very quick
> sequence, the following happens:
>
> deleting 3
> deleting 4
> deleting 5
>
> 5 deleted
> 5 deleted
> 5 deleted
>
> Here's the code:
>
> $('a.deletepm').click(function(){
>
>     id = $(this).attr('id');
>     console.log('deleting '+id);
>
>     $.ajax({
>         type: "POST",
>         url: "ajax.php?action=deleteprivatemessage",
>         data: "id="+id,
>         success: function(response){
>             console.log('comment '+id+' deleted.');
>         }
>     });
>     return false;
>
> });
>
> For some reason, the ID inside the ajax callback doesn't get the right
> values.. Any idea why this could be? Thanks in advance!

Reply via email to