• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax question

 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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?

Thanks!

Eddy

 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks!

Eddy
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways to do this.
You can consider server push technologies likehttp://en.wikipedia.org/wiki/Comet_(programming)

Polling every few seconds can be expensive.

If you do end up polling make sure the interval is sensible.

Is a user initiated status not a good solution?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gautam Velpula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I might need some schooling on this
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Holding a scarce resource open in case it's going to be needed is almost always more expensive than freeing it and using it only when needed.

The same applies to database connections -- that's why DB connections are pooled.

I would consider technologies like Comet only in very specific situations where it can be proved to be necessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic