简体   繁体   中英

Rebind Partial View Elements after Ajax call

$('#approveRequest').on('click', function () {
        $.ajax({
            url: $('#approveRequest').data('url'),
            type: 'post',
            success: function(result) {
                $('#accountGroupAdmin').html(result);
            }
    });
    });

How do I rebind the elements are the partial view is refreshed ?

You can use event delegation with jquery.on . The static parent should remain during refresh.

$('staticParentIdCouldBeBody').on('click', '#approveRequest', function () {
        $.ajax({
            url: $('#approveRequest').data('url'),
            type: 'post',
            success: function(result) {
                $('#accountGroupAdmin').html(result);
            }
    });
});

Delegated events

Delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time. By picking an element that is guaranteed to be present at the time the delegated event handler is attached, you can use delegated events to avoid the need to frequently attach and remove event handlers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM