gpt4 book ai didi

jquery - jQuery套接字- 'An attempt was made to use an object that is not, or is no longer, usable'

转载 作者:行者123 更新时间:2023-12-03 11:59:56 29 4
gpt4 key购买 nike

我正在尝试学习使用套接字。我没有发现任何有关此错误的信息,或者正在搜索错误的关键字。无论如何,我可以连接到我的套接字,但是当我尝试发送消息时出现此错误:

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable



$('#send-btn').click(function(){ //use clicks message send button    
var mymessage = $('#message').val(); //get message text
var myname = $('#name').val(); //get user name

if(myname == ""){ //empty name?
alert("Enter your Name please!");
return;
}
if(mymessage == ""){ //emtpy message?
alert("Enter Some message Please!");
return;
}

//prepare json data
var msg = {
message: mymessage,
name: myname,
color : '<?php echo $colours[$user_colour]; ?>'
};
//convert and send data to server
websocket.send('hello');
});

我找不到有关此错误的任何信息,或者我再次犯了同样的错误,并搜索了错误的关键字。无论如何,我希望你们中的一些人对我能做些什么或为我指出正确的方向有一个答案。

最佳答案

您调用websocket.send()函数的速度太快。

当websocket网络状态有效或已建立时,您应该调用它。

您可以尝试通过setTimeout(调用websocket.send方法和time的函数)进行调用。

关于jquery - jQuery套接字- 'An attempt was made to use an object that is not, or is no longer, usable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33652526/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com