[英]How to create simple “CHAT APP” using Flask-SocketIO, Python, Javascript?
How can I edit these codes so that when I click the button, the input texts will be appended to the empty unordered lists and be able to broadcast to other "users"?如何编辑这些代码,以便当我单击按钮时,输入文本将附加到空的无序列表并能够广播给其他“用户”?
<body>
<ul>
</ul>
<input type="text" id="myMessage">
<button>Send</button>
</body>
document.addEventListener('DOMContentLoaded', () => {
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);
socket.on('connect', () => {
});
socket.on('announce chat', data => {
});
});
app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("index.html")
@socketio.on("submit chat")
def chat(data):
Well you dont call your submit chat and you should format it like submit_chat not with white space in between.好吧,您不要调用您的提交聊天,并且应该将其格式化为 submit_chat 而不是中间有空格。
On your socket.io script you dont have submit_chat called you do have announce chat...在您的 socket.io 脚本上,您没有 submit_chat 调用,您确实有宣布聊天...
socket.on('submit_chat', data => {
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.