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

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -