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 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

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.