Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails g:remoteLink response

Tags:

grails

How can I get the response from an ajax call made with g:remoteLink, using jquery ?

I have tried using nSuccess="removeTask(e)" and getting the response with e.responseText or e.response, but nothing works.

like image 538
cripox Avatar asked Feb 20 '11 13:02

cripox


1 Answers

When using Grails with the JQuery plug in and using the remote functions like remoteLink, the code that is generated for the remote function is something like this:

success: function(data, textStatus){ jQuery('#results').html(data); }

This is if for example you set the update parameter as "[success:'results']". As you can see the main function receives a data parameter which I think is what your looking for, so if you need to call another function that uses that value, you could do something like this:

<g:remoteLink controller="yourcontroller" action="youraction" update="[success: 'results']" onSuccess="yourFunction(data) ">Your link</g:remoteLink>

This will generate javascript code like this:

success:function(data,textStatus){ jQuery('#results').html(data); yourFunction(data); }

Hope this helps!!

like image 141
Maricel Avatar answered Nov 04 '22 03:11

Maricel