Search code examples
ajaxgrailsgsp

Is it possible to render json data into a javascript variable while making an ajax call in grails?


Is it possible to render json data into a javascript variable while making an ajax call in grails?

I am using the submitToRemote inorder to make an ajax call from my grails view to an action in my grails controller. The action returns a json variable/value. I need to to assign this value to a javascript variable for further usage on my web page. Is this possible to achieve? Any leads will be helpful.


Solution

  • submitToRemote have the onSuccess option that you can use to retrieve the json data. From the docs:

    onSuccess (optional) - The JavaScript function to call if successful

    An example of how doing it can be seen in this blog post.