Answer the question
In order to leave comments, you need to log in
Loading data via AJAX?
Good day, colleagues and other Khabrovites!
Here's a problem I faced 5 years ago. In our time, the solution to this problem is almost everywhere, the entire Internet is permeated with this used technology like a galaxy far, far away by the Force.
It's about AJAX.
So, 5 years ago I had the task of dynamically loading data (for chat). Of course I used AJAX. Every 5 seconds, a request was sent to the server, in response, XML was issued or a text document convenient for the parser using JS (not JSON, I had not heard of it then).
Time has passed, and it seems to me that something in this area has undergone evolution at least (well, for example, they did something in terms of reducing the load on the server, other than just increasing the capacity of the server and expanding the channel).
Tell me, dear Web developers in the subject, how is dynamic loading of data from the server implemented now? Also by timeout? A good example of implementation, yes, everyone’s “favorite” VK.
ps: I use jQuery in my work. What will be loaded: XML, JSON (P) or a whole piece of html (partial representation) - it doesn’t matter.
pps: give me some ideas, of course I can look at the js-code of VK, but suddenly it's all obfuscated
Answer the question
In order to leave comments, you need to log in
At the moment, there are newer technologies such as websocket and long polling.
Websocket will definitely work faster and, as for me, even more interesting than simple ajax with timeouts.
signalr.net/ - here's a link for you. If the browser has support for websockets, then it works through them, otherwise through long polling.
If you have a chat, websockets is the best choice.
Here is actually a good review article
www.insight-it.ru/tekhnologii/soobshheniya/postoyannoe-soedinenie-mezhdu-brauzerom-i-serverom/
Here is a simple implementation, you can still find a dozen others more complicated.
habrahabr.ru/post/124119/
Implementation on Node.js - socket.io/
Here, depending on the capabilities supported by the client, graceful degradation occurs, i.e. the most efficient of the available transports is selected.
The following transports are currently supported:
- websockets
- flash socket
- ajax long polling
- AJAX multipart streaming
- infinite iframe
- ajax polling
websocket, I have already seen what was not already mentioned in the comments above, but I want to add.
1) There are web sockets and their flash replacement, which makes web socket technology cross-browser. Crutches, but where without them.
2) The advantage of websockets is that the server can send a message, not just the client.
3) A bunch of ready-made tools, especially for node.js.
If your application is Just for fun, dig into web sockets.
I am implementing a toy where the communication between the client and the server is via websockets. Very happy with the new technology. Even with a slow internet, websockets show good results.
It all depends on which AP you plan to use. Promising websocket and long polling technologies do not work correctly on all PLs, there are many obvious shortcomings. If you want to work with these technologies, then immediately check your PL for correct operation.
If you don't have a requirement for an "instant" update, it's better to use good old AJAX, so there will be less hassle. jQuery does a great job of providing all the mechanisms for working with Ajax.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question