javascript - socket.io client receives everything except for one emitter
问题描述
I have got client and server socket.io code. Every message is being received except for one handler: when i send the following to the client:
socket.on('loginb', function(login) {
console.log(1);
var a = bedrijven.filter(function(e) {
return e.bedrijfsnaam == login.bnaam && e.pwd == login.pwd;
});
if (a[0] == null||a.length!=1||a==undefined) {
socket.emit('wow', false);
} else {
console.log(2,a);
socket.emit('wow', a[0]);
}
});
everything until "412" will be logged, but the message won't be received. This is how the listener looks at the client side:
socket.on('wow', function(login) {
console.log(26);
});
26 is never getting logged.
The strange thing is: the emitter and the listener are on the same place as other emitters and listeners i have, and work the same. However, this does not work while the rest does.
I also tried replacing socket.emit('wow', a[0]);
by socket.emit('wow', 'string');
but no difference.
解决方案
I found the answer thanks to @jfriend00's comment. Indeed, the problem was that the client did not receive the socket message because the page refreshed after the submit. This was prevented by adding a return statement at the end of the submit function.
推荐阅读
- tensorflow - OpenCV keras 模型引发错误“__init__() 得到了一个意外的关键字参数‘ragged’”
- python - 如何通过vpn和使用ssl在python(没有vpc)中使用aws lambda访问外部mysql数据库
- haskell - 使用组合函子的应用实例
- android - 如何设置 RecyclerView 项目相对于父项的最大高度
- c# - Windows.Gaming.Input.RawGameController 初始化为错误状态
- java - 在上下文菜单选择中从 android listview 获取项目
- java - 在 Java 中对从文件中读取的数据进行求和
- mysql - MySQL 查询适用于 SELECT 但不适用于 UPDATE 语句
- r - lm.fit 中的错误(x,y,offset = offset,singular.ok =singular.ok,...):'x' 中的 NA/NaN/Inf
- microservices - 如何设计需要与他人通信的微服务