We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43220
    • 4 Posts
    Hi,
    I have an ajax call. I want to get a chunk in this ajax call. In this chunk it contains a snippet.


    My chunk looks like:

    <div > this is the content [[!mySnippet]] </div>

    It seems that it does not execute the snippet. It returns
    this is the content [[!mySnippet]]
    and not executed snippet.

    I have tried
    getChunk(), parseChunk()
    seems not working.
    I have many chunks so i do not want to create resources for each chunks. Is there any way to do it ?

    Thanks,
    Awlad
      Best Regards,
      Awlad
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      What is the target URL of your AJAX call?

      I would have one snippet with as many functions as necessary to return each desired output, and it would accept arguments from the AJAX request to determine which function to run (using a PHP switch construct). That way you'd only need one resource to be the target URL, and MODX would take care of everything. No need for multiple chunks (unless you want to use them as mini-tpls for the output of each function) or multiple snippets.

      The function library could even be a separate .php file that gets included by the main snippet.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 43220
        • 4 Posts
        Quote from: sottwell at Sep 08, 2014, 01:17 AM
        What is the target URL of your AJAX call?

        I would have one snippet with as many functions as necessary to return each desired output, and it would accept arguments from the AJAX request to determine which function to run (using a PHP switch construct). That way you'd only need one resource to be the target URL, and MODX would take care of everything. No need for multiple chunks (unless you want to use them as mini-tpls for the output of each function) or multiple snippets.

        The function library could even be a separate .php file that gets included by the main snippet.

        I have 10 different languages. So if i use resource then i need 10 different resources for each ajax call. I have made common system for ajax request and it sent request to a php file( not in resource) and i have get all result correctly. In this case i have found that snippets inside chunk is not executed.
          Best Regards,
          Awlad
          • 43220
          • 4 Posts
          I have solved it runSnippet. I have set placeholder in the chunk. executed snippet and replace placeholder with the sniipet result. It is working now smiley
            Best Regards,
            Awlad
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Ah. I use migxMultiLang, so I only have one resource for each language; it uses TVs for the translated fields.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 28042 ☆ A M B ☆
              • 24,524 Posts
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org