问题
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