自学内容网 自学内容网

websocket接收文心一言示例

简单示例demo 接受文心一言返回过来的数据

<html>
<body>
<div id="nr"></div>
</body>
<script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js">  </script>
<script>
ws = new WebSocket("ws://127.0.0.1:2000"); //开启websocket
ws.onopen = function() {
    alert("连接成功");
    ws.send('tom'); //向服务器发送字符
    alert("给服务端发送一个字符串:tom");
};
ws.onmessage = function(e) {
    //alert("收到服务端的消息:" + e.data);
    $("#nr").append(e.data);   //接收返回过来的数据并追加页面上
    console.log(e.data);
};
</script>
</html>


原文地址:https://blog.csdn.net/f897907070/article/details/142529552

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!