Skip to content

Instantly share code, notes, and snippets.

@timneutkens
Last active April 15, 2021 12:10
Show Gist options
  • Save timneutkens/004f8ac0f963068fa718e8397877194e to your computer and use it in GitHub Desktop.
Save timneutkens/004f8ac0f963068fa718e8397877194e to your computer and use it in GitHub Desktop.
Magento2 | Execute data-mage-init and x-magento-init in dynamic content (ajax request)

Execute data-mage-init and x-magento-init in dynamic content (ajax response)

Trigger .trigger('contentUpdated') on the element where dynamic content is injected.

$.ajax({
    url: 'https://www.example.com',
    method: 'POST',
    data: {
        id: '1'
    },
    success: function (data) {
        $('.example-element').html(data)
                             .trigger('contentUpdated')
    }
});
@richardcalahan
Copy link

bro....you rock

@lc122218679
Copy link

friend
you so rock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment