简体   繁体   中英

JavaScript in Grails's GSP page

how I can run impromtu js code inside the grails g:if statement? I want to run Error alert windows or success alert window. my code is

<g:if test="${flash.error}">
    <g:javascript>invokePopup(${flash.error})</g:javascript>
</g:if>

and in my main.js

function invokePopup(message) {
   $.prompt(message);
}

nothing happened in this case and YES, a added main.js to ApplicationResources.groovy

Assuming that flash.error contains a String value the following line needs to change to avoid unexpected identifier errors.

<g:if test="${flash.error}">
    <g:javascript>invokePopup("${flash.error}")</g:javascript>
</g:if>

Notice that flash.error is now outputted inside quotes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM