Is there a way to make <g:link calls POST instead of GET?

柔情痞子 提交于 2019-12-24 16:23:15

问题


I'm using a

<g:link ...

tag for a button that I would like to send as POST instead of GET for security reasons.

Is there a way to do this? I cannot use

<g:actionSubmit 

because I'm using Twitter Bootstrap's Glyphicons (i.e. I need to put the icon in between the tag, it can't go in a value attribute)

<g:link class="btn btn-success" action="someAction" id="class.id"> <i class="icon-ok"></i> Save </g:link>

So, I need a link that I can pass the ID as POST and includes a tag structure like:

<g:someTag ... > SOME LABEL </g:sometag>

Thanks for any help on this matter!


回答1:


1.My suggestion is to use Ajax before the g:link it self handels the call to the action and controller

like:

<g:link class="btn btn-success"  id="class.id" onclick='UsingPost();'>SOME LABLE HERE </g:link>
<script type='text/javascript'>
function UsingPost(){
    jQuery.ajax({
        type:'POST',
        data:{"model":${pleaseUseTheModelyouHaveLoaded}"}, 
        url:'${createLink(action: 'save')}',
        success:function(data,textStatus){
        jQuery('#success').html(data);},
        error:function(XMLHttpRequest,textStatus,errorThrown){}
        });
}
</script>

or refer to this post https://stackoverflow.com/questions/17360606/grails-spring-security-core-ajax-authentication




回答2:


Another way is to use g:remoteLink. It defaults to using POST

<g:remoteLink action="someAction" id="${someObj.id}" update="saveStatus">Save</g:remoteLink>


来源:https://stackoverflow.com/questions/17678748/is-there-a-way-to-make-glink-calls-post-instead-of-get

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