使用websocket/socket.io进行部分页面刷新
已安装websocket和socket.io以在我的网站中运行IM并进行部分页面刷新。IM已编码,工作正常。 要进行部分页面刷新,我在服务器中对其进行了编码:使用websocket/socket.io进行部分页面刷新,socket.io,Socket.io,已安装websocket和socket.io以在我的网站中运行IM并进行部分页面刷新。IM已编码,工作正常。 要进行部分页面刷新,我在服务器中对其进行了编码: // receive and broadcast log or monitors update socket.on('sendUpdate', function(ID) { io.sockets.emit('getUpdate', ID); }); 在客户机中: // send update log or
// receive and broadcast log or monitors update
socket.on('sendUpdate', function(ID)
{
io.sockets.emit('getUpdate', ID);
});
在客户机中:
// send update log or monitors to the server
function sendUpdate(ID) // for log and monitors table changes
{
socket.emit('sendUpdate', ID); // send it to the server for broadcast to all clients
};
// receive log or monitors update
function getUpdate(ID)
{
// how to do this???
};
那么,如何在不刷新整个页面的情况下按id更新html元素呢?
感谢您的建议。用什么刷新?您的意思是仅从服务器重新加载该html元素?我想那是不可能的。但是,如果您发送/接收要显示/刷新的数据,则可以使用该数据更新元素:
$('#'+ID).html('任何您想要更新的内容')这是您想要的吗?使用('getUpdate',函数(数据){…})的socket.on('getUpdate',function(data){…})代码>