Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between websocket and ajax

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what is the difference between websocket and ajax". It is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "what is the difference between websocket and ajax".

Differences: 1, ajax is a development technology for creating interactive applications, websocket is a protocol used to realize full-duplex communication between browser and server; 2, ajax establishes short connection, websocket establishes long link; 3, ajax is used for non-real-time data exchange, websocket is used for real-time data exchange.

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

1. The essence is different.

Ajax, namely Asynchronous JavaScript and XML, is a web page development technology for creating interactive web applications.

WebSocket is a new protocol of HTML5, which realizes full-duplex communication between browser and server. Its essence is to shake hands through the HTTP/HTTPS protocol and then create a TCP connection for exchanging data, and the server communicates with the client in real time through this TCP connection.

two。 The life cycle is different.

Websocket establishes a persistent connection, which remains connected throughout a session, while ajax is a short connection, which is disconnected after the data is sent and accepted.

3. Different scope of application

Websocket is generally used for real-time data exchange between front and back end, but not real-time data exchange at front and back end of ajax.

4. The sponsors are different.

Ajax technology requires the client to initiate a request (the data users who request it can see it for themselves), while the WebSocket server and the client can push information to each other. (user A requests to return something A user can see B user can also see; if it belongs to the public, then everyone can see

5. Usage is 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 () are all the contents of this article entitled "what's the difference between websocket and ajax". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report