我正在编写一个与 websocket 服务器通信的客户端。目前,套接字服务器将生成的“令牌”发送给客户端,然后客户端将其设置为存储:
localStorage.setItem('token', json.token);
Run Code Online (Sandbox Code Playgroud)
并重定向到下一页,该页面在加载时运行以下代码:
token = localStorage.getItem('token')
console.log(token)
socket.send(JSON.stringify({"type": "getplayerinfo", "token": token}));
Run Code Online (Sandbox Code Playgroud)
在执行 console.log(token) 时,我得到了令牌。但是,当通过套接字发送令牌时,我得到:
Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable
Run Code Online (Sandbox Code Playgroud)
我已经调试了三天了,伤透了我的大脑。有小费吗?