Ajax simple question

I have a very simple question about ajax. If I want to update a specific area of ​​my site, I would prefer ajax to be the best way.

But is there anyway, instead of having javascript periodically check for changes on the server, the server would send data when some kind of event occurs?

I would like the client not to periodically send requests, but instead the server would send information only to the client, who, in turn, would have some kind of event listener.

Thank you in advance

+4
source share
6 answers

Yes, it can be done. It is called push or push streaming.

Here is one website that offers the opportunity to do this: InstantPush . And a short quote from their homepage:

“InstantPush is used to create web pages and mobile phones go live. They will be instantly updated in real time when the change occurs on the server side. Standard web connection makes updates go through firewalls and proxies. Without any modules on the client side!

InstantPush has been used since 2001, before Ajax was invented. This is probably the first Ajax Push Framework.

InstantPush leads the market in Northern Europe. "

Here is another company offering this technology: LightStreamer . And a quote from your homepage:

"Lightstreamer is a scalable and reliable server for transferring live data to Rich Internet Applications

Based on the comet and real-time network paradigm, it transmits real-time data to any web browser and client expression. HTML, HTML5, AJAX, Flex, Silverlight, Java, .NET, iOS, Android, and BlackBerry applications can easily receive data from the Lightstreamer Server.

"Lightstreamer is used in many mission-critical manufacturing systems where scalability, low network impact, bandwidth management, adaptive streaming and other advanced features have proven fundamental."

+1
source

This cannot be done because the http protocol works by sending a request and receiving a response from the server, so the server cannot respond without receiving the request.

+1
source

This is not possible using traditional HTTP. However, you can use a lengthy survey or one of his siblings to simulate push behavior.

0
source

This is a really tricky question when a server transfers or transfers data to clients without a request. HTTP is stateless, and even if the browser is a registered client, it still needs to be requested either through the code or through some tags, such as meta refresh. New, but still not very stable options are comet or websites.

The answer is a comet, not websockets. Yes it is possible. Another way is to use a browser.

This is an exception to the Push Technology wiki page.

* Apple Push Notification Service * BOSH * Comet * Client–server model * File transfer * Pull technology * Push Access Protocol * Push e-mail * Reverse Ajax * Streaming media * WebSockets 
0
source

No, this cannot be done. The server's task is to serve the results of a query that should start with.

0
source

I think websockets is the way to go, but is not yet supported for all browsers.

I used them with ruby ​​and chrome and was pretty simple.

0
source

Source: https://habr.com/ru/post/1332220/


All Articles