1. Essentially different
Ajax, asynchronous JavaScript and XML, is a Web development technique for creating interactive Web applications;
WebSocket is HTML5 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. Different scope of application
WebSocket is generally used for real-time data interaction between front and back, while Ajax is not real-time data interaction.
4. Different promoters
Ajax technology requires client-initiated requests, and WebSocket servers and clients can push information to each other.
5. Different usage
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 ()
Resources:
http://blog.csdn.net/qiuhuanmin/article/details/50719114
Https://www.cnblogs.com/zhongzihao/p/7859785.html
Analysis of the difference between WebSocket and Ajax