wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax question" Watch "Ajax question" New topic
Author

Ajax question

eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
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

Joined: Feb 16, 2010
Posts: 67
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gautam Velpula
Greenhorn

Joined: Aug 04, 2008
Posts: 13
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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

Joined: Aug 04, 2008
Posts: 13
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax question
 
Similar Threads
JSTL or JQuery plug-ins?
How to display Ajax result on the same jsp page
Tracking XMLHTTPRequest
how to call javascript function on body load using jquery
SEO and AJAX