remoteLink
Purpose
Creates a link that uses Ajax to call a remote function when clicked
Examples
Example controller for an application called shop
:
class BookController {def list() { [books: Book.list(params)] }
def show() { [book: Book.get(params.id)] }
def bookByName() { [book: Book.findByName(params.bookName)] } }
Example usages for above controller:
<g:remoteLink action="show" id="1">Test 1</g:remoteLink><g:remoteLink action="show" id="1" update="[success:'success',failure:'error']" on404="alert('not found');">Test 2</g:remoteLink>
<g:remoteLink action="show" id="1" update="success" onLoading="showSpinner();">Test 3</g:remoteLink>
<g:remoteLink action="show" id="1" update="success" params="[sortBy:'name',offset:offset]">Test 4</g:remoteLink>
As a method call in GSP:
my link = <%= remoteLink(action: 'show', id: 1,
update: 'success', onFailure: 'showError();')
{ "this is the link body" } %>
Description
Attributes
action
(optional) - the name of the action to use in the link; if not specified the default action will be linkedcontroller
(optional) - the name of the controller to use in the link; if not specified the current controller will be linkedid
(optional) - The id to use in the linkfragment
(optional) - The link fragment (often called anchor tag) to usemapping
(optional) - The named URL mapping to use to rewrite the linkparams
(optional) - a Map containing request parametersupdate
(optional) - Either a Map containing the elements to update for 'success' or 'failure' states, or a string with the element id to update, in which case failure events would be ignoredbefore
(optional) - The JavaScript function to call before the remote function callafter
(optional) - The JavaScript function to call after the remote function callasynchronous
(optional) - Whether to do the call asynchronously (defaults to true)method
(optional) - The method to use the execute the call (defaults to POST)
Events
onSuccess
(optional) - The JavaScript function to call if successfulonFailure
(optional) - The JavaScript function to call if the call failson_ERROR_CODE
(optional) - The JavaScript function to call to handle the specified error code (eg on404="alert('not found!')"). With Prototype, this prevents execution ofonSuccess
andonFailure
.onUninitialized
(optional) - The JavaScript function to call if Ajax fails to initialiseonLoading
(optional) - The JavaScript function to call when the remote function loads the responseonLoaded
(optional) - The JavaScript function to call when the remote function completes loading the responseonComplete
(optional) - The JavaScript function to call when the remote function completes, including any updates
Source