2011-11-22 19 views
0

在我的gsp頁面中,單擊圖像後,我想將某些內容保存到數據庫,但不想離開該頁面/重定向。這可能使用Grails嗎?沒有重定向的Grails調用函數

使用此:

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

回答

2
<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> 

對於這個AJAX功能,你需要jQuery插件:

grails install-plugin jquery 

如果你沒有安裝JavaScript庫,該remoteLink會回落到一個正常的鏈接。您需要將庫包含到您的html-<head><g:javascript library="jquery" />

+0

嘿。感謝您的快速回答。我嘗試了你的方法,頁面確實令人耳目一新。是否滿足?並且onComplete也沒有顯示 – recoInrelax

+0

你有沒有安裝jQuery插件? – Chris

+0

這一個:http://grails.org/plugin/jquery? – recoInrelax