recoInrelax
recoInrelax

Reputation: 707

Grails call function without redirect

In my gsp page, after clicking on an image, i want to save something to the database but don't want to leave that page / redirect. Is that possible using Grails?

Using this:

<g:link action="addF" params="[prog: it3.id]" onclick="return confirm('${message(code: 'Are you sure you want to add this as favourite ?')}');">
                                &nbsp;&nbsp;&nbsp;<img src="${resource(dir:"images", file: "f.png") }" width="21" height="18"/>
                                </g:link>

Upvotes: 0

Views: 1645

Answers (2)

Chris
Chris

Reputation: 8099

<g:remoteLink 
    action="addF"
    params="[prog: it3.id]"
    before="if (!confirm('${message(code: 'Are you sure you want to add this as favourite ?')}')) return false;"
    onComplete="alert('Marked as favorite')">
      <img src="${resource(dir:'images', file: 'f.png') }" width="21" height="18"/>
</g:remoteLink>

For this AJAX functionality you require jQuery plugin:

grails install-plugin jquery

If you have no javascript library installed, the remoteLink will fall back to a normal link. You will need to include the library into your html-<head>: <g:javascript library="jquery" />

Upvotes: 2

zoran119
zoran119

Reputation: 11327

Have you considered using Ajax? http://grails.org/doc/1.3.7/ref/Tags/remoteFunction.html

Upvotes: 2

Related Questions