Magento 2 : How to call text/x-magento-init on Ajax success
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
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 ??
uicomponent jquery knockoutjs magento-2.2.5 requirejs
add a comment |Â
up vote
3
down vote
favorite
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 ??
uicomponent jquery knockoutjs magento-2.2.5 requirejs
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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 ??
uicomponent jquery knockoutjs magento-2.2.5 requirejs
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 ??
uicomponent jquery knockoutjs magento-2.2.5 requirejs
uicomponent jquery knockoutjs magento-2.2.5 requirejs
asked 3 hours ago
Narendra
729
729
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
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/
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
add a comment |Â
up vote
1
down vote
Try like
var contentBlock = this.element.find('.page-footer');
$.ajax(
url: this.options.contentsUrl,
type: 'GET',
dataType: 'html',
data:
'form_key': FORM_KEY,
node: node.id
,
context: contentBlock,
showLoader: true
).done(function (data)
contentBlock.html(data).trigger('contentUpdated');
);
OR
$('.page-footer').append(row).trigger('contentUpdated');
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
 |Â
show 2 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
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/
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
add a comment |Â
up vote
2
down vote
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/
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
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/
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/
answered 29 mins ago
Narendra
729
729
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
add a comment |Â
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Narendra for posting answer, +1 for your answer.
– Ramkishan
25 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
Thanks @Ramkishan
– Narendra
17 mins ago
add a comment |Â
up vote
1
down vote
Try like
var contentBlock = this.element.find('.page-footer');
$.ajax(
url: this.options.contentsUrl,
type: 'GET',
dataType: 'html',
data:
'form_key': FORM_KEY,
node: node.id
,
context: contentBlock,
showLoader: true
).done(function (data)
contentBlock.html(data).trigger('contentUpdated');
);
OR
$('.page-footer').append(row).trigger('contentUpdated');
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
 |Â
show 2 more comments
up vote
1
down vote
Try like
var contentBlock = this.element.find('.page-footer');
$.ajax(
url: this.options.contentsUrl,
type: 'GET',
dataType: 'html',
data:
'form_key': FORM_KEY,
node: node.id
,
context: contentBlock,
showLoader: true
).done(function (data)
contentBlock.html(data).trigger('contentUpdated');
);
OR
$('.page-footer').append(row).trigger('contentUpdated');
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
 |Â
show 2 more comments
up vote
1
down vote
up vote
1
down vote
Try like
var contentBlock = this.element.find('.page-footer');
$.ajax(
url: this.options.contentsUrl,
type: 'GET',
dataType: 'html',
data:
'form_key': FORM_KEY,
node: node.id
,
context: contentBlock,
showLoader: true
).done(function (data)
contentBlock.html(data).trigger('contentUpdated');
);
OR
$('.page-footer').append(row).trigger('contentUpdated');
Try like
var contentBlock = this.element.find('.page-footer');
$.ajax(
url: this.options.contentsUrl,
type: 'GET',
dataType: 'html',
data:
'form_key': FORM_KEY,
node: node.id
,
context: contentBlock,
showLoader: true
).done(function (data)
contentBlock.html(data).trigger('contentUpdated');
);
OR
$('.page-footer').append(row).trigger('contentUpdated');
edited 3 hours ago
answered 3 hours ago


Hit's
753219
753219
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
 |Â
show 2 more comments
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Tried but no luck :( not getting where I am wrong
– Narendra
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Did you get any response into response.categoryProducts?
– Hit's
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
Yes I am getting whole Html in its response, and all html content is displaying correctly accept that x-magento-init block. And that script with x-magento-init is also I am getting in response, I have checked by console log whole data
– Narendra
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
try this $('.page-footer').append(response.categoryProducts).trigger('contentUpdated'); In which file you ahve write this code?
– Hit's
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
Actually we have used Amasty extension for shop by ajax, so I am writing this amasty extension js file i.e. amShopbyAjax.js
– Narendra
3 hours ago
 |Â
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f248677%2fmagento-2-how-to-call-text-x-magento-init-on-ajax-success%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password