Passing parameters to the View - From Grails to Javascript -
Passing parameters to the View - From Grails to Javascript -
from controller passing parameter view.
when print parameter body gets printed correctly. however, if seek print parameter javascript function doesn't work.
how can right ?
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 </body>
the reason why alert doesn't show outputting value constant instead of valid string within javascript. need wrap in quotes , should encode string value utilize javascript.
for example:
var str = '${pinstance.stringval?.encodeasjavascript()}'; alert(str);
javascript grails
Comments
Post a Comment