Skip to content

Instantly share code, notes, and snippets.

@daniel-ifrim
Forked from timneutkens/README.md
Created July 27, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-ifrim/c6d6a563be45d2a73a58c62e62784432 to your computer and use it in GitHub Desktop.
Save daniel-ifrim/c6d6a563be45d2a73a58c62e62784432 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')
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment