I'm a beginner and I'm writing a js function that every 1 second it calls a PHP script where it checks some values on mysql DB, PHP encodes them in Json, then JS again decode it and throw them into html.
I have two questions for you:
-Why do you think this code is not properly working? It only writes the first value into the <p>
list.
-How can I make this scalable? Every call to the php script executes a query. I need something like realtime, but I think using this way I'll destroy my server soon xD
JS
setInterval(function(){
$.getJSON("php/checkstatus.php", function(result){
$("#status").html(result['status']);
$("#tempint").html(result['tempint']);
$("#tempext").html(result['tempext'] + " ");
$("#humidityext").html(result['humidityext'] + " ");
});
},1000);
The json is like this:
{"status":"0","tempext":"25","tempint":"150","humidityext":"65"}
and the HTML is like this:
<p>status: <span id='status'>xx</span> .</p>
<p>Inside temperature: <span id='tempint'>xx</span> °C</p>
<p>Outside temperature: <span id='tempext'>xx</span> °C</p>
<p>Outside humidity: <span id='humidityext'>xx</span> </p>