[英]Socket is called multiple times
我阅读了有关此问题的其他问题,但没有找到解决问题的方法。 我看到您可以例如删除removeListeners或将套接字代码移出单击处理程序,但这似乎不适合我的问题。
我正在使用套接字+ ajax。 我的代码逻辑如下:
//client side
button.onclick = function () {Communicate(info);return false;};
function Communicate(info) {
// ajax call
}
// server side -> receive ajax
app.post("/...",function(req,res) {
// do stuff (...)
// send global socket call
io.sockets.emit("GlobalCall",xx);
// return ajax call to the user who triggered this
res.send(...));
});
// client side again
socket.on("GlobalCall",function(x)) {
// this is called twice sometimes for some reason... It should be called only once each time the server emits ...
}
正如我在代码中评论的那样,服务器仅发出一次,但“ GlobalCall”有时会发出两次。 有什么帮助吗? 谢谢
该解决方案实际上与套接字无关。 发生的事情与为每个分配的属性执行两次的jquery动画有关。 我不知道,也没有注意到。 怪罪插座。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.