简体   繁体   中英

How to use g:message from Javascript

There are some messages coming from a Javascript file to a GSP page. How can I implement g:message in a Javascript page?

For example:

if ($('#name').val() == "") {
    $('#nameStatus').show();
    $('#nameStatus').html('<font color=red>Company Name can not be blank</font>');
    return false;

Try this kind of syntax :

function foo() {
    return "${message(code:'my.message.code')}";
}

If I understand correctly, you want to be able to use the output from g:message in your javascript.

There is a very helpful blog post which talks about how to use g:createLink in a similar way that you want, so you can easily adapt it to use g:message as well. Check out the post here , there is some useful info in the comments as well.

The idea is to create javascript objects in your GSP file; which should be defined before including your javascript file; and then just access those global objects in your js code.

Edit:

You might also be interested in the GSParse Plugin . I haven't tried it my self but I think it accomplishes what you are looking for as well.

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