Ajax 圣杯;带有动态更新的remoteFunction会导致HTML页面中出现空值

Ajax 圣杯;带有动态更新的remoteFunction会导致HTML页面中出现空值,ajax,grails,groovy,Ajax,Grails,Groovy,我有一个关于在java脚本函数中使用remoteFunction组件的问题;我正在使用Grails1.3.7 我在一个包含我想要更新的div的页面中有几个div。我要更新的每个div都有自己的id(fullUrlSaProfilDivX),其中X是唯一的,并且在页面中是唯一的id 我想更新两个div(一个接一个) 我创建了一个java脚本函数: <g:javascript> function removeSelectedProfilAssoc(urlSaId, profilAssoc

我有一个关于在java脚本函数中使用remoteFunction组件的问题;我正在使用Grails1.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>
我做错什么了吗?如何传递要刷新的div的id并将其添加到刷新的div中

谢谢你看


本杰明

啊哈,你把javascript和gsp搞混了。我也做过很多次,这可能很难发现

在您的例子中,
urlsayd
是一个javascriptvar,但是您在GSP函数调用中使用它,因此它将是
null

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

new Ajax.Updater('fullUrlSaProfilDiv'+urlSaId,'/_Pong2WAR/profilAssoc/delete',{asynchronous:false,evalScripts:true,parameters:'id='+profilAssocId});
我建议直接构建这个
Ajax.Updater(…)
,而不使用remoteFunction(或类似的东西):


函数removeSelectedProfilAssoc(urlsayd,profilAssocId){
新的Ajax.Updater('fullUrlSaProfilDiv'+urlsayd,${createLink(action:“delete”,controller:“profilAssoc”)},{asynchronous:false,evalscript:true,parameters:'id='+profilAssocId});
新的Ajax.Updater('lightUrlSaProfilDiv'+urlsayd',${createLink(action:'listUrlSaProfil',controller:'profilAssoc')},{asynchronous:true,evalscript:true,parameters:'urlSa.id='+urlsayd});;
};

另一方面,我现在总是使用jquery,它简化了GSP中的所有ajax。

ahah,你把javascript和GSP混为一谈了。我也做过很多次,这可能很难发现

在您的例子中,
urlsayd
是一个javascriptvar,但是您在GSP函数调用中使用它,因此它将是
null

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

new Ajax.Updater('fullUrlSaProfilDiv'+urlSaId,'/_Pong2WAR/profilAssoc/delete',{asynchronous:false,evalScripts:true,parameters:'id='+profilAssocId});
我建议直接构建这个
Ajax.Updater(…)
,而不使用remoteFunction(或类似的东西):


函数removeSelectedProfilAssoc(urlsayd,profilAssocId){
新的Ajax.Updater('fullUrlSaProfilDiv'+urlsayd,${createLink(action:“delete”,controller:“profilAssoc”)},{asynchronous:false,evalscript:true,parameters:'id='+profilAssocId});
新的Ajax.Updater('lightUrlSaProfilDiv'+urlsayd',${createLink(action:'listUrlSaProfil',controller:'profilAssoc')},{asynchronous:true,evalscript:true,parameters:'urlSa.id='+urlsayd});;
};

另一方面,我现在总是使用jquery,它简化了GSP中的所有ajax

 jQuery.ajax({
     type:'POST',
     data:'territorio='+territorio_id+'&anho='+anho+'&id='+firstIndicador+'&div='+divId+'&divmap='+divmap, 
     url:'/observatoriograils/eje/indGeneralporAnhoyTerritorio',
     success:function(data,textStatus){jQuery('#'+divId).html(data);},
     error:function(XMLHttpRequest,textStatus,errorThrown){}}); 

其中数据是参数,url是/url/controller/function,divId是用于更新的div的名称

 jQuery.ajax({
     type:'POST',
     data:'territorio='+territorio_id+'&anho='+anho+'&id='+firstIndicador+'&div='+divId+'&divmap='+divmap, 
     url:'/observatoriograils/eje/indGeneralporAnhoyTerritorio',
     success:function(data,textStatus){jQuery('#'+divId).html(data);},
     error:function(XMLHttpRequest,textStatus,errorThrown){}}); 

其中data是参数,url是/url/controller/function,divId是用于更新的div的名称

谢谢!这正是我现在需要的。谢谢!这正是我现在需要的。
 jQuery.ajax({
     type:'POST',
     data:'territorio='+territorio_id+'&anho='+anho+'&id='+firstIndicador+'&div='+divId+'&divmap='+divmap, 
     url:'/observatoriograils/eje/indGeneralporAnhoyTerritorio',
     success:function(data,textStatus){jQuery('#'+divId).html(data);},
     error:function(XMLHttpRequest,textStatus,errorThrown){}});