1👍
✅
adding the original code to the ready block is either not working?
socket.onopen = function() {
console.log("socket open")
socket.send("hello world");
}
It could be that the channel is not yet opened
0👍
That’s code that worked
socket = new WebSocket("ws://127.0.0.1:8000/chat/");
socket.onmessage = function (e) {
alert(e.data);
};
$(document).ready(function () {
socket.onopen = function() {
$('button').click(function () {
socket.send($('#mes_input').val());
});
}
});
Source:stackexchange.com