Magento 2 – How to Call text/x-magento-init on Ajax Success

jqueryknockoutjsmagento-2.2.5requirejsuicomponent

I am in need to trigger some script with "text/x-magento-init" on ajax call but I am unable to do so.

trigger('contentUpdated') 

contentUpdated is also not working in my case.

I am using contentUpdated as:

$('.page-footer').html(response.categoryProducts);                        
$('.page-footer').trigger('contentUpdated');

On console log(response.categoryProducts) I can see that x-magento-init script but the effect is not shown on frontend on using this way.

Any help ??

Best Answer

I found a solution for my question at last. I used 'applyBindings()' as 'contentUpdated' was not working in my case. Like

$('.page-footer').replaceWith(data.categoryProducts);
$('.page-footer').trigger('contentUpdated');
if ($.fn.applyBindings != undefined) {
      $('.page-footer').applyBindings();
}

Hope that this may help some one else as well. For more details have a look at this link: https://codeblog.experius.nl/magento-2-uicomponent-reinit-ajax-reload/