Automatically update web application when data is updated on server
Is it possible to send update (or automatic response) from a SERVER to a WEB APPLICATION?
I have a SERVER that updates data every 5 min (sometimes random). I want to update the new data on a running WEB APPLICATION without making a request from brower to server.
Right now I execute an ajax request every 5min so that I can update the latest data. But sometimes no data is updated. Also, sometimes the data gets updated at eg. 9:01 am and the update executes at eg. 9:05am. What i would like to do is: immediately update web application when the data gets updated on the server.
Any ideas on how this could be implemented? I can use any technolog开发者_高级运维y/language or anything that is required to do this.
Regards
You’re describing HTTP server push technology. There are many ways to implement it, but knowing what it’s called should help you get started.
I believe you want to use this model: http://en.wikipedia.org/wiki/Comet_(programming)
The client-server relationship cannot be reversed. The browser has to be the one to initiate any communication.
However, you can quite easily poll the server at short interval to ask "has anything changed?". Then, according to the result, you could refresh all or part of the data with a second AJAX call.
You can try SQL server notification, but you have to do a lot of business logic around it.
精彩评论