failed: WebSocket is closed before the connection is established.
来源:12-14 Nginx+uWSGI+Daphne部署Django Channels应用
李嘉图principal
2020-09-03
打开控制台看了下如下
报错:
WebSocket connection to ‘ws:/ws/message/lars/’ failed: WebSocket is closed before the connection is established.
我查了下Provisional headers are shown好像是说请求没能发出去
js中这么写的
initwebsocket(){
const ws_scheme = window.location.protocol === "https:" ? "wss" : "ws";
const ws_path = ws_scheme + "://"+ window.location.host+ '/ws/message/'+`${this.current_talk_obj}/`;
const ws = new ReconnectingWebSocket(ws_path);
const that = this;
// 监听后端发送过来的消息
ws.onmessage = function (event) {
const data = JSON.parse(event.data);
console.log(data);
console.log(data.sender,that.current_talk_obj);
if (data.sender === that.current_talk_obj) { // 发送者为当前选中的用户
that.Get_conversation();
console.log('get new info')
// 将接收到的消息插入到聊天框
// scrollConversationScreen(); // 滚动条下拉到底
}
}
和老师的比对了也没发现什么问题,请老师帮忙看下,谢谢
写回答
1回答
-
您好,验证一下你定义的“ws_path”是否有效呢,看后端有写这个websocket的连接吗
112020-09-08
相似问题