【发布时间】:2018-08-28 18:48:18
【问题描述】:
我尝试用烧瓶作为项目制作简单的聊天应用程序,所以我有页面
当用户创建新的聊天室时,聊天室会显示给所有其他用户
所以我有这个代码,但是 socket.emit 不能用它
我的意思是烧瓶应用程序没有收到数据这里是代码
document.addEventListener('DOMContentLoaded',function () {
// Connect to websocket
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port+'/channels');
// When connected, configure buttons
socket.on('connect', function () {
document.querySelector("#create").onclick=function (){
const new_channel=document.querySelector("#new_chanell").value;
const channels_list=document.querySelector("#channels");
for (let i=0; i<channels_list.length;i++){
if(channels_list[i].value==new_chanell){
document.querySelector("h1").innerHTML="this channel allready here";
return false;}
}
socket.emit('add_channel', {'channel': new_channel});
document.querySelector("h1").innerHTML="new channel";
return false;
}});
在烧瓶中
@socketio.on("add_channel")
def add_channel(data):
raise("he")
channel=data["channel"]
channel_list.append(channel)
emit("new_one",{"channel":channel},broadcast=True)
所以我输入 raise("he") 以了解应用程序是否收到数据但没有
该函数根本没有调用为什么
【问题讨论】: