开发者

Ajax simple question

I have a very simple question about ajax. If I'd like to refresh a particular area of my site I supose ajax would be the best way.

But is there anyway instead of having a javascript periodically checking for changes on the server, the server would send the data when a given event would happen?

What I'd like was the client not needing to send requests periodically but instead the serve开发者_开发知识库r would only send the info to the client which in turn would have some kind of event listener.

Thanks in advance


Yes, this can be done. It is referred to as "push" or "push streaming".

Here is one website that offers the ability to do this: InstantPush. And a brief quote from their home page:

"InstantPush is used to make web pages and mobile phones go live. They will instantly be updated in real time when a change occurs at the server side. Standard web communication makes updates pass firewalls and proxies. Without any modules at the client side!

InstantPush has been used since 2001, before "Ajax was invented". It is probably the First Ajax Push Framework.

InstantPush is leading the market in northern Europe."

Here is another company offering this technology: LightStreamer. And a quote from their home page:

"Lightstreamer is a scalable and reliable Server for pushing live data to Rich Internet Applications

Based on the Comet and Real-Time Web paradigms, it streams real-time data to any Web browser and client application. HTML, HTML5, AJAX, Flex, Silverlight, Java, .NET, iOS, Android, and BlackBerry applications, can easily receive live data from Lightstreamer Server.

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


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


No this cannot be done. A server's job is to serve up results from a request, one that it must have to begin with.


That is not possible using traditional HTTP. You can, however, use long polling or one of its siblings to simulate push behaviour.


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

I used them with ruby and chrome and was pretty easy.


this is indeed a difficult ask where server broadcasts/pushes data to clients without being requested. HTTP is stateless and even if browser is a registered client, it still needs to request either through code or through some tags like meta refresh. New but still not so stable options are Comet or websockets.

Answer is Comet rather than websockets. YES, it is possible. Another way is using Browser plugin.

This is an except from wiki page at Push Technology

* 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜