Christopher Reid
Christopher Reid

Reputation: 4482

NODEJS/socket.io emit not fired

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)

Upvotes: 0

Views: 117

Answers (1)

Frederico
Frederico

Reputation: 91

You should use socket.on() other than io.on()

io.on('connection', function(socket){  
       socket.on('pw', function(data){
          console.log(data)
       });
   });

Upvotes: 1

Related Questions