If I write
<g:link controller="book" action="list">Book List</g:link>
in GSP it will render to something like
<a href="/book/list">Book List</a>
in HTML.
But what if I wish to call this URL with AJAX? I don't need <a>
tag anymore, I need only url /book/list
.
How to compute it?
Note that it should depends on application context, trailing slash etc.
答案 0 :(得分:2)
请改用createLink,这是doc
一些例子:
// generates "/shop/book/show/1"
<g:createLink action="show" id="1" />
// generates "/shop/book/show?foo=bar&boo=far"
<g:createLink action="show" params="[foo: 'bar', boo: 'far']"/>
// generates "/shop/book"
<g:createLink controller="book" />
// generates "/shop/book/list"
<g:createLink controller="book" action="list" />
// generates "/shop/book/list"
<g:createLink url="[action:'list',controller:'book']" />