简体   繁体   中英

Grails g:remoteLink response

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM