Update PHP variable without refresh
<p>I am new in JSON and PHP programming. I am making a web page that allows to view data from <strong>file.py</strong>, those data will be linked in a <code>gauge</code> and updated <code>second by second</code>.</p>

<pre><code>  var gauge1;
  var x = &lt;?php echo python /home/usr/Desktop/file.py ?&gt; ;

    setInterval(function() {
      gauge1.refresh(x);
    }, 1000);
  };
</code></pre>

<p>I can make the gauge shows just the first reading from "file.py" but is stuck there, the only way to update the gauge is refreshing the page and the new reading is shown in the gauge.</p>

<p>I think the problem is in:</p>

<blockquote>
  <p>gauge1.refresh(x);</p>
</blockquote>

<p>because when I write:</p>

<blockquote>
  <p>gauge1.refresh(getRandomInt(0,50));</p>
</blockquote>

<p>The gauge always show random data, updating a new <code>random data between 0 and 50</code>.</p>

<p>Is there any solution to make the gauge always shows automatically data from <strong>file.py</strong> without refresh the page?</p>

<p>You can use ajax to execute a backend script in a time interval like this .</p>

<pre><code>var x=null;
setInterval(retriveData, 300000); 
function retriveData() {
   $.ajax({url: "pyData.php", success: function(data){
      x=data;
   }});
}
</code></pre>

<p>And your Php code like this <strong>(pyData.php)</strong></p>

<pre><code>&lt;?php 
 $command = escapeshellcmd('/home/usr/Desktop/file.py');
 $output = shell_exec($command);
 echo $output;
 ?&gt;
</code></pre>

<p>You can execute like this </p>

javascript php python html json