ajax - Cereal ;动态更新的remoteFunction在HTML页面中导致null

标签 ajax grails groovy

我有一个关于在Java脚本函数中使用remoteFunction组件的问题;我正在使用Grails 1.3.7。

我的页面上有几个div,其中包含我要更新的div。我要更新的每个div都有自己的ID(fullUrlSaProfilDivX),其中X是,页面中的唯一ID。

我想更新两个div(一个接一个)。

我创建了一个Java脚本函数:

<g:javascript>
function removeSelectedProfilAssoc(urlSaId, profilAssocId) {
    ${ remoteFunction (action:"delete", update:'fullUrlSaProfilDiv'+urlSaId, controller:"profilAssoc", params:'\'id=\'+profilAssocId', options:[asynchronous:false]) };
    ${ remoteFunction (action:"listUrlSaProfil", controller:"profilAssoc", update:'lightUrlSaProfilDiv'+urlSaId, params:'\'urlSa.id=\'+urlSaId') };
};
</g:javascript>

通过链接调用:
<a href="javascript:void(0)" class="icons_delete" onclick="removeSelectedProfilAssoc(${profilAssocInstance?.urlSa?.id}, ${profilAssocInstance?.id})"></a>

我想更新与按钮链接的div(具有唯一ID的链接)。

我不知道为什么在生成的页面中我得到null而不是id并且div不刷新:
function removeSelectedProfilAssoc(urlSaId, profilAssocId) {
    new Ajax.Updater('fullUrlSaProfilDivnull','/_Pong2WAR/profilAssoc/delete',{asynchronous:false,evalScripts:true,parameters:'id='+profilAssocId});;
    new Ajax.Updater('lightUrlSaProfilDivnull','/_Pong2WAR/profilAssoc/listUrlSaProfil',{asynchronous:true,evalScripts:true,parameters:'urlSa.id='+urlSaId});;
};

难道我做错了什么 ?如何传递要刷新的div的ID并将其刷新后添加?

谢谢您的光临!

本杰明

最佳答案

啊哈,您混合使用javascript和gsp。我也做了很多次,要找出来可能很棘手!

在您的情况下,urlSaId javascript var,但是您在 GSP 函数调用中使用了它,因此它将是null...。

不幸的是,解决方法并不容易,因为remoteFunction不允许您在更新中正确连接javascript变量,因为您想要的是:

new Ajax.Updater('fullUrlSaProfilDiv'+urlSaId,'/_Pong2WAR/profilAssoc/delete',{asynchronous:false,evalScripts:true,parameters:'id='+profilAssocId});

我建议的是不使用remoteFunction(或类似方法)直接构建此Ajax.Updater(..):
<g:javascript>
  function removeSelectedProfilAssoc(urlSaId, profilAssocId) {
    new Ajax.Updater('fullUrlSaProfilDiv'+urlSaId,'${createLink(action:"delete", controller:"profilAssoc")}',{asynchronous:false,evalScripts:true,parameters:'id='+profilAssocId});
    new Ajax.Updater('lightUrlSaProfilDiv'+urlSaId,'${createLink(action:"listUrlSaProfil", controller:"profilAssoc")}',{asynchronous:true,evalScripts:true,parameters:'urlSa.id='+urlSaId});;
  };
</g:javascript>

现在,我总是使用jquery代替它,它简化了GSP中的所有ajax。

关于ajax - Cereal ;动态更新的remoteFunction在HTML页面中导致null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638028/

相关文章:

php - 使用ajax更新股票价格

php - 使用向上和向下键突出显示从 php ajax 搜索中获取的搜索文本

grails - 在NetBeans中创建Grails项目时出错

grails - Grails:findAllBy动态方法-高级排序属性

javascript - 使用 javascript 将 html 写入新窗口

javascript - 在 selectize JS 中设置当前倍数

testing - Grails 测试 JMS 消息传递

gradle - 测试时gradle环境变量中的URISyntaxException

java - 将数据表与交互相结合

regex - 逃逸美元