user752746
user752746

Reputation: 617

AJAX post twice

I have an unordered list with a delete link. When the link is click an AJAX call trigger to delete the record and remove the item from the list. My AJAX call works but I notice in Firebug that it’s making the same call twice.

Anyone one knows what I’m doing wrong here? Thank you in advance for you help!

Here's my UL:

<UL>
    <li id="10">
        Test action <a class="deleteAction" href="10">delete</a>
    </li>
    <li id="11">
        Test action <a class="deleteAction" href="11">delete</a>
    </li>
</UL>

Here's my script:

$('.deleteAction').click(function(){
    var deleteActionID = $(this).attr("href");

    $.post(
        'cfc/test.cfc?method=deleteActionByID&returnformat=plain', 
        { id: deleteActionID }, 
        function(data){
            alert(data);
        }
    );
    return false
});

Upvotes: 1

Views: 1028

Answers (1)

Nick G.
Nick G.

Reputation: 1175

I think your href is causing the listitem to be "clicked" again, engaging the jquery command the second time. That is, you click the listitem and the jquery and the href are both activated and then the href "clicks" the listitem again, re-engaging your jquery script. You might need to change this use of href in order to fix this.

Upvotes: 2

Related Questions