JQuery $ .ajax works for the first time, but not on subsequent clicks

Everything works fine the first time you click the delete link, but subsequent clicks delete only the record without updating the div "quotes".

I’m not sure that I don’t notice here.

My .js file is:

$('.deleteRow').live('click', function (e) {
    if (confirm('Delete?')) {
        $.ajax({
            type: 'POST',
            url: this.href,
            cache: false,
            dataType: 'html',
            success: function (response) {
                $('#quotes').replaceWith(response);
                $('#quotesTable').tablesorter().tablesorterPager({ container: $('#pager'), positionFixed: false });
            }
        });
    }
    return false;
});

and html:

<tr>
    <td>
        Now is the time for all good men to come to the aid of their parties.
    </td>
    <td>

    </td>
    <td>
        7/6/2010 10:13:44 PM
    </td>

    <td> <a class="editRow" href="/Quote/Edit/2">Edit</a></td>
    <td> <a class="deleteRow" href="/Quote/Delete/2">Delete</a></td>
</tr>

<tr>
    <td>
        I&#39;m a loser
    </td>

    <td>
        146
    </td>
    <td>
        7/6/2010 9:11:42 PM
    </td>
    <td> <a class="editRow" href="/Quote/Edit/1">Edit</a></td>
    <td> <a class="deleteRow" href="/Quote/Delete/1">Delete</a></td>
</tr>
+3
source share
1 answer

I view this on an iPhone, so I cannot see all your code, but you should probably use ".html" instead of ".replaceWith". The former replaces the contents inside the specification tag; the latter also wipes the tags.

+5
source

Source: https://habr.com/ru/post/1757510/


All Articles