1. Essentially different Ajax, asynchronous JavaScript and XML, is a Web development technique for creating interactive Web applications; WebSocket is a new protocol that implements full-duplex communication between the browser and the server. The essence is to create a TCP connection for exchanging data after shaking hands with the HTTP/HTTPS protocol, and the server communicates with the client in real time through this TCP connection. 2. Life cycle is different. WebSocket establishes a long connection that remains connected in a single session, while Ajax is a short connection that is disconnected when data is sent and accepted. 3. Scope of application WebSocket is generally used for real-time data interaction between front and back, but not real-time data interaction between Ajax and front end. 4. Initiator different AJAX technologies require client-initiated requests, and WebSocket servers and clients can push information to each other. 5. Usage of different Ajax:$.ajax ({type: "post", url: "Http://localhost:8080/target", data: "state = yes", DataType: "JSON", success: Funciont (data) {}}); Websocket:var monitor = new WebSocket ("ws://" +ip+path) OnOpen (), OnMessage (), OnClose () Reference: http://blog.csdn.net/ qiuhuanmin/article/details/50719114
An analysis of the difference between WebSocket and Ajax