我有以下代码:
ws = new WebSocket("ws://localhost:8080/websocket");
ws.onmessage = function(e) {
alert(e.data);
};
function send() {
ws.send('test');
}
window.addEventListener("load", function() {
document.getElementById("form").addEventListener("submit", send);
});

<!doctype html>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>
<script src="ws-client.js"></script>
</head>
<body>
<form id="form">
<input type="text" id="t" value=""/>
<button type="submit">send</button>
</form>
</body>
</html>
&#13;
我得到&#34;在页面加载时,与ws:// localhost:8080 / websocket的连接被中断。 WS-client.js:2:0&#34;尝试将消息发送到服务器时。
此代码在Chrome下正常运行。
在我的服务器端,我可以看到握手成功,服务器已收到消息并发送了响应。
这是握手:
Request URL: http://localhost:8080/websocket
Request Method: GET
Status Code: HTTP/1.1 101 Switching Protocols
Request Headers:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: HuqIhI8DVOJu7PvhnHafJg==
Pragma: no-cache
Origin: null
Host: localhost:8080
Connection: keep-alive, Upgrade
Cache-Control: no-cache
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Response Headers:
Upgrade: websocket
Sec-WebSocket-Accept: 8ZD23MLEK3DgLPuEoRl+6UPtdg8=
Connection: Upgrade
你知道怎么了吗?谢谢!