【问题标题】:How to use variables within a JSON object with JustGage如何通过 JustGage 在 JSON 对象中使用变量
【发布时间】:2016-03-20 17:11:59
【问题描述】:

我快疯了,希望有人能帮忙。我有一个使用 getJson 函数通过 Jquery 访问的数组。

我试图弄清楚如何访问和使用 json 对象中的变量。我想将变量与名为justgage 的javascript 插件一起使用。

这是我在 my_url.php 上的数组

  <?php

$my_data=array(min=>"100",max=>"200", total=>"50");

// sending output
header('Content-Type: text/json');
echo json_encode($my_data,true);
?>

这是我获取数组的代码

<script>
$(document).ready(function(){
  $("button").click(function(){
$.getJSON("my_url.php",function(result){
 $.each(result, function(key, value){
                $("#showdata").append(key+value);
            });
        });
    });
});
</script>

这给了我

min100max200total50

我想知道如何将这些数据放入下面justgage脚本所需的变量中?

<script>

  var g = new JustGage({
    id: "gauge",
    value: total,
    min: 0,
    max: 100,
    title: "Sample Data"
  });
</script>

【问题讨论】:

  • 在我看来,result 你想要的,已经。

标签: javascript php jquery justgage


【解决方案1】:
<script>
  $(document).ready(function(){
   $("button").click(function(){
     $.getJSON("my_url.php",function(result){
         var g = new JustGage({
          id: "gauge",
          value: result.total,
          min: result.min,
          max: result.max,
          title: "Sample Data"
       });
      });
    });
  });
</script>

【讨论】:

  • 哇,它立即生效。太棒了,非常感谢。
猜你喜欢
  • 2021-06-16
  • 2015-08-15
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多