1

解决了!使用我的代码!

我只是不能使用 Ajax 来刷新我在 JustGage 中的结果。我检查了 Stackoverflow 上的另一篇文章,但这不起作用。你能告诉我我在最后一个 setInterval 函数上做错了什么吗?谢谢!

马特

    <!doctype html>

        <html>
          <head>
            <title>Customize style</title>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

            <style>
              body {
                text-align: center;
              }


              p {
                display: block;
                width: 450px;
                margin: 2em auto;
                text-align: left;
              }
            </style>
            <script src="resources/js/raphael.2.1.0.min.js"></script>
            <script src="resources/js/justgage.1.0.1.min.js"></script>
            <script src="resources/js/jquery-1.9.1.min.js"></script>
            <script>
              var g1;

              window.onload = function(){
              var g1 = new JustGage({
                id: "g1", 
                value: getRandomInt(500, 600), 
                min: 0,
                max: 1500,
                title: "CO",
                label: "ppm",    
                gaugeWidthScale: 0.3          
              });

 var myvar='';
$.ajax({
    type:'post',
    url: 'g1CO.php',
    dataType:'text',
    success: function(data) {
        useReturnData(data);
    }
});

function useReturnData(data){
    myvar = data;
    console.log(myvar);
};



         setInterval(function() {
          //$.get('g1CO.php', function(data) { g1.refresh(myvar); });
        $.get("g1CO.php", function(data) {  g1.refresh(data)});   
        }, 2500);
      };
            </script>

            </head>
          <body>

        <table border="0">
        <tr>
        <td><div id="g1" style="width:300px; height:200px"></div></td>

        </tr>
        </table>
4

1 回答 1

0

使用g.refresh(newValue).

  var g1, g2;

  window.onload = function(){

    var g1 = new JustGage({
      id: "cpugauge", 
      value: 0, 
      min: 0,
      max: 100,
      title: "CPU",
      label: "Load"
    });

    var g2 = new JustGage({
      id: "memgauge", 
      value: 0, 
      min: 0,
      max: 100,
      title: "Memory",
      label: "Used"
    });

    setInterval(function() {
        $.get('ajax/cpu.php', function (newValue) { g1.refresh(newValue); });
        $.get('ajax/mem.php', function (newValue) { g2.refresh(newValue); });          
    }, 2500);
  };
于 2017-01-21T02:04:57.437 回答