I am trying to access the returned object from grrovy controller into my javascript code.
Here's the code.
Groovy Controller:
def result = [
data : 'data',
status : 'success',
]
[result: result]
GSP file:
<g:hiddenField name="result" value="${result}" />
JS file:
var jsresult = $("#result").val();
console.log(jsresult);
console.log(jsresult.data);
Here's the console output:
{data=data, status=success}
undefined
Looks like some issue with formatting but not able to find out the root cause. Tried converting it into JSON but still not able to access the properties (jsresult.data).
Please let me know how I can resolve this and let me know if any alternate way of passing data from groovy controller to JS code.
Thanks.
jsresultis aString, not a JS object sojsresult.datais like"some string value".data.jsresultis coming as String. Not sure how to convert it into an object and access its properties.