【问题标题】:grails remotefunction: can't access paramsgrails remotefunction:无法访问参数
【发布时间】:2013-04-25 15:18:34
【问题描述】:

我的 GSP 文件中的 javaScript 函数中有一个 remoteFunction 调用:

function fnCreateEntitiesPerForceChart() {
      var interval = $("#entitiesPerForceTimeIntervalSelect").val();
      interval = escape(interval);
      var url = '${createLink(controller: 'federation', action: 'createEntitiesPerForceChart')}?interval='+interval;
      $("#entitiesPerForceChart").attr("src", url);
alert("interval is: " + interval);
      ${remoteFunction(controller: 'federation', 
        action: 'getEntitiesPerForceTable', 
        params: '\'interval\''+':'+interval, 
        onSuccess: 'fnUpdateEntitiesPerForceTable(data,textStatus)')}; 
    }

当我检查页面源时,远程函数会创建以下代码:

try{DojoGrailsSpinner.show();}catch(e){} dojo.xhr('Get',{content:{'interval':null}, preventCache:true, url:'/FederationReporter/federation/getEntitiesPerForceTable', load:function(response){  fnUpdateEntitiesPerForceTable(data,textStatus); }, handle:function(response,ioargs){try{DojoGrailsSpinner.hide();}catch(e){} }, error:function(error,ioargs){try{DojoGrailsSpinner.hide();}catch(e){}  } });; 

为什么我的变量被'null'替换了?

谢谢!

【问题讨论】:

  • 我在页面源代码中找不到您的函数调用。函数fnUpdateEntitiesPerForceTable 被调用,而你的函数被调用fnCreateEntitiesPerForceChart。你能更详细地解释一下你的问题吗?
  • 我是否可以假设您同时使用 Jquery 和 dojo 插件?如果不是,那么很可能您是单独使用 dojo 插件并尝试对选择器使用 jquery 语法,这可能不起作用...

标签: javascript ajax grails dojo


【解决方案1】:

remoteFunction 呼叫中尝试使用params

params: '\'interval\': + interval'

【讨论】:

    【解决方案2】:

    试试这个:

    function fnCreateEntitiesPerForceChart() {
      var interval = dojo.byId("entitiesPerForceTimeIntervalSelect").get("value");
      // [...] rest of your code
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多