[英]NODEJS/socket.io emit not fired
This should be simple, but for some reason my socket.emit will not execute on button press. 这应该很简单,但是由于某些原因,我的socket.emit不会在按下按钮时执行。 I know the sumbit button event listener is working. 我知道sumbit按钮事件侦听器正在工作。 What am I missing? 我想念什么?
index.js index.js
io.on('connection', function(socket){
io.on('pw', function(data){
console.log(data)
});
});
index.html 的index.html
var submit = document.querySelector('input[type=submit]')
submit.addEventListener('click',function(){
socket.emit('pw', 'pw', function(){
console.log('clicked')
})
},false)
You should use socket .on() other than io.on() 您应使用插座 。对()比其他io.on()
io.on('connection', function(socket){
socket.on('pw', function(data){
console.log(data)
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.