Hello, I'm using the Socket i.o and when I send a POST / EnviaTemperatura, it is not automatically updating on my site. What am I doing wrong?
Node.js
app.post('/EnviaTemperatura', function(req, res){
temperatura = req.body.temp;
console.log(temperatura);
res.send('Temperatura: ' + temperatura);
});
io.on("connection", function(socket) {
socket.emit('RecebTemp', temperatura);
});
HTML
<div class="col-xs-9 text-right">
<div class="huge"><span id="EnviaTemp">0</span> ºC</div>
<div>Temperatura no Interior da casa</div>
</div>
<script>
var socket = io();
socket.on('RecebTemp', function (temperatura) {
document.getElementById("EnviaTemp").innerHTML = temperatura;
});
</script>
In my case, it is only updating when I do a Refresh on the page. But I did not want to refresh the entire page, only in this DIV, since I have other elements on the screen that take a while to load.
What could it be?