开发者

grails gsp javascript integration, how to escape variables?

开发者 https://www.devze.com 2023-04-11 21:34 出处:网络
I have a gsp page (template) where I need to include some javascript. In the example below, how would I get the remoteFunction to understand, the moneyTransId will be set by the javascript function?Mo

I have a gsp page (template) where I need to include some javascript. In the example below, how would I get the remoteFunction to understand, the moneyTransId will be set by the javascript function? MoneyTransId comes out fine in the alert, but I can't get it to work in the remoteFunction, and apparently need to escape it somehow.

<script type="text/javascript">
function confirmVoid(moneyTransId) {
  开发者_JAVA技巧 var r = confirm("Please confirm the void");
   if (r == true) {
        alert("ID is: " +moneyTransId);
        ${remoteFunction(action:"voidTransaction", id:moneyTransId)};
          ...


Use the following syntax:

${remoteFunction(action:'voidTransaction', params:'\'id=\'+moneyTransId')};

This way, you won't mix server-side code with client-side code. Hope this helps.


Server side variables and statements can not read client side (javascript) variables. Server side code runs first, then html and javascript get generated and sent to the client (browser). Then the browser renders HTML and runs javascript. Hope this helps your thought process. Dmitry.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号