This should be simple, but for some reason my socket.emit will not execute on button press. I know the sumbit button event listener is working. What am I missing?
index.js
io.on('connection', function(socket){
io.on('pw', function(data){
console.log(data)
});
});
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('connection', function(socket){
socket.on('pw', function(data){
console.log(data)
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.