Reputation: 833
I am using the jquery library with the grails remoteFunction tag to make an AJAX call in the event of a mouseover. The from a println I wrote I know the designated action is being called, but the onSuccess function is never triggered. I checked firebug and I am receiving a 404 error. I am new to AJAX and JS in general, so I might be overlooking something very obvious right now. Here is my code snippet.
gsp:
<script type="text/javascript">
function change()
{
document.getElementById('changer').src='${resource(dir: "images/images", file: "heart_red.png")}';
}
function onSuccess(data){
alert("Has hearted:");
}
<img class="user_profile_pic" src="${user.profilePicture}" onmouseover="${remoteFunction(controller:'user', action: 'hasHearted', onSuccess: 'onSuccess(data)', params:[userID: user.id])}"/>
groovy:
def hasHearted = {
println "Recieved user ID: $params.userID"
if(some condition...){
[hasHearted: true] as JSON
}
else{
[hasHearted: false] as JSON
}
}
Upvotes: 0
Views: 1855
Reputation: 1376
Try to use render method in the controller:
render ([hasHearted: true] as JSON)
Upvotes: 1