dimanche 1 mars 2015

nodejs update page on loading

I have a site developed in php, javascript and nodejs. When a user click on a button I would like to restart a countdown inside all page. It works fine, the problem is on mobile, when a user is loading the page and another click on the button, the page in loading doesn't take the new value of countdown.


The page loads in some seconds not so much but can be a real problem.


This is my client code:



Date.prototype.addHours= function(h){
this.setHours(this.getHours()+h);
return this;
}

socket = io.connect( 'http://ift.tt/1AG0JLY' );
socket.on('restart', function(data) {
$('#countdown').val(new Date().addHours(4));
});


server code:



var express = require('express');
var app = express();
var server = app.listen(8080);
var io = require('socket.io').listen(server);

io.sockets.on( 'connection', function( client ) {
client.on( 'restart', function( data ) {
console.log( 'Message auction received ' + data.idAsta + ":" + data.bidGiocati +":" + data.winner);

//client.broadcast.emit( 'message', { name: data.name, message: data.message } );
io.sockets.emit( 'restart', { id: data.id } );
});
});


How can I solve this problem?


Thanks


Aucun commentaire:

Enregistrer un commentaire