How to use g:message from Javascript

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 13:11:50

问题


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;

回答1:


Try this kind of syntax :

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



回答2:


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.



来源:https://stackoverflow.com/questions/8292582/how-to-use-gmessage-from-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!