Discuss / JavaScript / ws.on is not a function?

ws.on is not a function?

Topic source

Gingbery

#1 Created at ... [Delete] [Delete and Lock User]

如题,按照教程中的代码写法会报错,但是写成 ws.onopen =function(){} 又完全没效果

lonelykid1984

#2 Created at ... [Delete] [Delete and Lock User]

教材中的API是ws这个包的。在浏览器上用的话是浏览器实现的websockets协议,按照W3C规范。参考这个http://www.runoob.com/html/html5-websocket.html

子胥人家

#3 Created at ... [Delete] [Delete and Lock User]

嗯嗯,这个问题我也困惑了一阵,看了回复清晰些了,on()这个是ws包的,是为了便于测试的;onopen()是在编写浏览器客户端时的写法。所以有ws.on is not a function,改成onopen以后我这边就正常了。


  • 1

Reply