【问题标题】:JQuery - add some parameters to a hrefJQuery - 向href添加一些参数
【发布时间】:2015-06-02 12:51:26
【问题描述】:

我正在尝试向方法发送一些参数,但我不知道如何转换内容以使我的 java 方法理解我想让她知道的内容。

我有这个 html 代码:

<label>info :</label>
@for((k,v)<- map){

@if(k == "humidity") {
                      <button id="hum" value="@k">@k</button> 
                      <button id="@v" class="h_id">@v</button>
                     }else{

                     }

@if(k == "temperature"){
                      <button id="temp" value="@k">@k</button> &nbsp;&nbsp;
                      <button id="@v" class="t_id">@v</button>
                    }else{

                    }

@if(k == "luminosity"){
                      <button id="lum" value="@k">@k</button>
                      <button id="@v" class="l_id">@v</button>
                    }else{

                    }
}

在 @k 中,我得到如下信息资源:humidity、temperature 或 luminosity,在 @v 中,我得到资源的 id。
在这个脚本中,我想获取所有这些信息并将其传递给
arduinoChartenv(String id,String id_t,String t_v,String id_h,String h_v,String id_l,String l_l):

 $(document).ready(function(){

    $(".chart").click(function(){

      var id_t = $(".t_id").attr('id');
      var t_v = $("#temp").val();
      var id_h = $(".h_id").attr('id');
      var h_v = $ ("#hum").val();
      var id_l = $(".l_id").attr('id');
      var l_l = $("#lum").val();

     alert("id temp : "+id_t+" val temp: "+t_v+" id hum : "+id_h+"val hum : "+h_v+"id lum : "+id_l+" val lum : "+l_l);
     //here I get the good values


     window.location.href = "@routes.Application.arduinoChartenv(id,"+id_t+","+t_v+","+id_h+","+h_v+","+id_l+","+l_l+")";
    // here I do not get those values

    });
  });

当我尝试打印传递给方法的值时, 例如:

   System.out.println(id_t);
   System.out.println(t_v);

我在终端中得到了这个:

+id_t+
+t_v+

我试过jQuery(".????").html();和.innerHTML...但没有好的结果...

【问题讨论】:

  • 你尝试过 AJAX 吗?
  • AJAX 它不是我的朋友。不能用 jQuery 完成吗?
  • 呵呵... AJAX with play其实很简单。
  • 你有例子吗?
  • 或者您可以将数据作为表单提交给 arduinoChartenv 函数,而不是使用 JQuery

标签: jquery parameters playframework href


【解决方案1】:

如果您的代码正在编译,我假设您的 arduinoChartenv() 方法需要 7 个参数,它看起来像这样.. arduinoChartenv(id,id_t,t_v,id_h,h_v,id_l,l_l) 您得到错误的结果是因为您没有将变量传递给方法,而是将变量名称作为字符串传递。例如在下面的代码行中

@routes.Application.arduinoChartenv(id,"+id_t+","+t_v+","+id_h+","+h_v+","+id_l+","+l_l+")"

您传递的不是 id_t 而是一个字符串 +id_t+ 。删除双引号和 id_t 周围的 + ,它应该可以工作。

【讨论】:

  • 不,它不会工作。我不知道为什么,但它不会看到变量的值......
猜你喜欢
  • 2018-04-15
  • 1970-01-01
  • 1970-01-01
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-20
相关资源
最近更新 更多