From my Controller i am passing a parameter to the view.
When i print the parameter from the Body it gets printed correctly. However, if i try to print the parameter from a Javascript function it doesn't work.
How can i correct this ?
Controller
def showpeople(Long id){
def pInstance = People.get(id)
render (view: "showpeople",model: [pInstance: pInstance])
}
View
<script>
$(document).ready(function(){
var str = ${pInstance.stringval}; // <--- DOESN'T WORK
alert (str); // <--- DOESN'T SHOW ALERT
)}
</script>
<body>
${pInstance.stringval} <--- PRINTS SUCCESSFULLy
</body>
var str = '${pInstance.stringval}';If it's a string you need to wrap it in quotes of some sort or the javascript will choke on it.