【问题标题】:Grails remoteFunction ajax assistanceGrails remoteFunction ajax 帮助
【发布时间】:2015-03-21 20:58:18
【问题描述】:

我真的很难使用remoteFunction在控制器上的函数中获取不断更新的进度百分比值以显示在模板 GSP 页面中。

这是我的控制器代码,“progressData”是从服务发送的,用于不断更新任务的当前进度:

def progress(progressData) {

   def statusToView = progressData

   [statusToView: statusToView]
}

在我的 _progress.gsp 页面中:

<g:javascript>
    setInterval( "refreshMe();", 300 );
    function refreshMe(){
       ${remoteFunction(action:'progress', controller:'data')}
    }
</g:javascript>

控制器期待属性progressData 不是从remoteFunction 获得的,所以我猜我必须考虑以另一种方式做到这一点,但我有点不知所措现在。另外,因此,我在 GSP 中没有得到 statusToView 的价值。

【问题讨论】:

    标签: ajax grails


    【解决方案1】:

    正如您所指出的,您的操作 progress 实际上正在等待未通过的 progressData 参数。 如果您的 progressData 值存储在您的 gsp 页面中的某个位置,您应该以这种方式或类似方式更改您的 remoteFunction:

    $remoteFunction(action: 'progress', controller: 'data', update: [success: 'great', failure: 'ohno'], params: '\'progressData=\' + progressData')
    

    关于update: [success: ... ]here可以找到各个属性的描述。

    【讨论】:

    • 谢谢,尝试执行上述操作,但我似乎总是失败,因为我的 statusToView 似乎永远不会在视图中更新
    • remoteFunction 在 Grails 3+ 中也被贬值了
    猜你喜欢
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多