An analysis of the difference between WebSocket and Ajax

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.