Skip to content

Instantly share code, notes, and snippets.

@btekbtek
Forked from timneutkens/README.md
Created March 8, 2019 10:12
Show Gist options
  • Save btekbtek/d77dfc28f9cefe242e3bc9ef65b4429f to your computer and use it in GitHub Desktop.
Save btekbtek/d77dfc28f9cefe242e3bc9ef65b4429f 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