简体   繁体   中英

Issue with passing parameters in socket.emit()

            document.querySelector('#sendmessage').onclick = () => {
                const channel = "sports";
                const name = document.querySelector('#displayname').data("displayname");
                const msg = document.querySelector('[name="message"]').value;
                const time = timeStamp();
                //message(n,d,t);
                socket.emit('updatemessage', {'channel':channel, 'name':name, 'msg':msg, 'time':time});
            }

I'm having issue with passing these four parameters (channel, name, msg, time) in socket.emit() part. I need to pass them over to store the message details over flask server. Am I allowed to pass more than one parameters? If not, how do I deal with this?

Edit: Flask snippet

@socketio.on('updatemessage')
def updatemessage(data):
    print("initialised")
    channel = data["channel"]
    name = data["name"]
    channels[channel][name][0] = data["msg"]
    channels[channel][name][1] = data["time"]
    print(f" this is the update channel info : {channels}")
    m = channels[channel]
    print(f"m is :  {m}")
    emit('message loader', m, broadcast=True)

Actually I'm trying to store the message data in global variable in flask server

Answering my own question!

I checked found out there was some problem with this line const name = document.querySelector('#displayname').data("displayname");

and now it's working perfectly. I was in belief that it must have been socket.emit() part that's creating the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM