Magento 2 : How to call text/x-magento-init on Ajax success

The name of the pictureThe name of the pictureThe name of the pictureClash 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 ??










share|improve this question



























    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 ??










    share|improve this question























      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 ??










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      Narendra

      729




      729




















          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/






          share|improve this answer




















          • Thanks @Narendra for posting answer, +1 for your answer.
            – Ramkishan
            25 mins ago











          • Thanks @Ramkishan
            – Narendra
            17 mins ago

















          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');





          share|improve this answer






















          • 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










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          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/






          share|improve this answer




















          • Thanks @Narendra for posting answer, +1 for your answer.
            – Ramkishan
            25 mins ago











          • Thanks @Ramkishan
            – Narendra
            17 mins ago














          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/






          share|improve this answer




















          • Thanks @Narendra for posting answer, +1 for your answer.
            – Ramkishan
            25 mins ago











          • Thanks @Ramkishan
            – Narendra
            17 mins ago












          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/






          share|improve this 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/







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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












          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');





          share|improve this answer






















          • 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














          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');





          share|improve this answer






















          • 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












          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');





          share|improve this answer














          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');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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
















          • 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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery