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

Delphi change the assembly code of a running process -

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

C++ 11 "class" keyword -