2013-06-13 1 views
1

해결되었습니다! 내 코드를 사용하십시오!JustGage - AJAX를 사용하여 PHP 스크립트를 새로 고칠 수 없습니다 (및 stackoverflow에서 사용할 수있는 작업 코드가 없습니다)

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> 
+0

www.jsfiddle.net을 제공 할 수 있습니다. – Muhammed

답변

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); 
    };