Grails g:remoteLink响应 [英] Grails g:remoteLink response

查看:59
本文介绍了Grails g:remoteLink响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery从使用g:remoteLink进行的ajax调用中获得响应?

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

我尝试使用nSuccess="removeTask(e)"并使用e.responseText或e.response获取响应,但是没有任何效果.

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

推荐答案

在将Grails与JQuery插件一起使用并使用诸如remoteLink之类的远程功能时,为远程功能生成的代码如下:

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>

这将生成如下的javascript代码:

This will generate javascript code like this:

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

希望这会有所帮助!

这篇关于Grails g:remoteLink响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆