Channels push callback in javascript

I am using phoenixframework channels to push a message, but I need to have a callback in javascript, here is my code but the callback is not working:

channel.push("insertion_completed", function (params)
  console.log('insertion_completed: ' + params);

What’s the right way to have a callback that will listen to the server response?


Remember there are 3 possible responses, ‘ok’, ‘error’, and ‘timeout’, you need to specify which or any combination or all of them. :slight_smile:

channel.push("insertion_completed", {})
  .receive('ok', function (msgID, msgData)
      console.log('insertion_completed: ' + msgData);

The push command takes the message id and the message data, right now you are passing the function as message data, which will not JSON-up well. ^.^

But you call receive on the resulted pending push to receive a message back, like ok. :slight_smile: