This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have an application that loads data from an outside source. The process takes several hours, and I'd like to continuously update the web page with messages saying something like "data loaded for account name1, data loaded for account name2" etc. etc. In other words the server is working, and I need to send data about this work from the server to the client without them refreshing the page.
Is AJAX the way to go? Does anyone have a code sample?
Joined: Feb 16, 2010
Anyone? Can AJAX even do this -- display a message to the user, and change it based on server developments -- without any interaction from the user?
What I mean is, I'd like AJAX to change a text field on the site, reflecting the current work done by the server. The process itself takes several hours, and the message would need to be updated every few seconds, so that the user can sit there and see that "data for name1 is loading... data for name2 is loading" etc.. Is that possible?
You can use an interval timer to periodically send an Ajax request that can return status of the operation -- assuming that the server code has some way to determine that status. DOM manipulation can then be used to update the display in any appropriate manner.
Gautam Velpula wrote:Polling every few seconds can be expensive.
Technologies such as Comet can be even more expensive as they hold the connection open for long periods.
Joined: Aug 04, 2008
Could you elaborate?
I have always been of the opinion one connection open to handle server side events is always more economical than opening and closing multiple connections which might not represent the state on the server.
While I have used both technologies and know wrong comet implementations can severely slow down applications. I have always found fault with the implementation rather than the concept itself.