2
votes

My gsp has a button and I am not submitting a form. When clicking the button, I want to call a n action in a controller and at the same time I have a jQuery code attached to that button. Even after calling an action in a Controller, hope it stays in the same view(not redirected to the page related to an action).

Any suggestion for a button? g:link, input button does not seem to fit.

Action I want to call is "myAction" and Controller that has 'myAction' is "myController". Thanks in advance.

2

2 Answers

3
votes

g:remoteLink is best solution to your problem dude, you call call jquery or javascript function upon success of your action, here addedCart is javascript function ,after action it gets executed successfully

  <g:remoteLink action="remoteCart" onSuccess="addedCart()" id="${product.id}">
        <img src="<g:resource dir="images" file="cart.gif"/> " rel="#mies1"/>
    </g:remoteLink>

Ref : grails doc

0
votes

The jQuery .get() funciton (see here) will call an abstract URL. If you are calling a JavaScript function alreary adding a call to .get() or similar (there many options in jQuery for calling URL).