Ajax call within rain template

in Development
Is it possible to make an Ajax call within a template and pass the response to a snippet .rain as a parameter?
Tags:
Is it possible to make an Ajax call within a template and pass the response to a snippet .rain as a parameter?
3 comments
Hey @mpisanchik, were you able to successfully make the API call?
You can find some information in some public documentation here: https://cruftlesscraft.com/passing-data-from-twig-to-javascript
Adrian Samuel
Software Developer
Lightspeed HQ
Hey @Adrian Samuel thanks for your response. I was able to make the AJAX call but the problem I was running into was that I wanted to pass the AJAX response (which is javascript) into a twig snippet. I know I can do the reverse which is passing from twig to javascript but I was wondering if it was possible to pass from javascript (AJAX) to twig.
Hey @mpisanchik ,
I imagine this isn't possible because the Twig is rendered server side from our back-end and the JS AJAX call happens client-side (on the browser only after the Twig has already loaded), so there isn't a way you could affect a change in the Twig output from a call that happens afterwards.
You would simply change the resulting HTML that generated with Javascript
Adrian Samuel
Software Developer
Lightspeed HQ