有没有办法使< g:链接调用POST而不是GET? [英] Is there a way to make <g:link calls POST instead of GET?
问题描述
我使用
< g:link ...
标记为我想发送为POST的按钮,而不是出于安全原因的GET。
有没有办法做到这一点?我不能使用
< g:actionSubmit
,因为我使用的是Twitter Bootstrap的Glyphicons(即我需要将图标放在标记之间,它不能进入值属性)
< g:link class =btn btn-successaction =someActionid =class.id> < i class =icon-ok>< / i>保存< / g:链接>
所以,我需要一个链接来传递ID作为POST,并包含一个标记结构,如:
< g:someTag ...>某些标签< / g:某标签>
感谢您对此事的任何帮助!
解决方案
1.我的建议是在g:之前使用Ajax链接它自己调用动作和控制器 h1>
like:
< g:link class =btn btn-成功id =class.idonclick ='UsingPost();'>一些可以在这里< / g:link>
< script type ='text / javascript'>
函数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>
或参考这篇文章
https://stackoverflow.com/questions/17360606/grails-spring-security-core-ajax-authenticationI'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.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
这篇关于有没有办法使< g:链接调用POST而不是GET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!