0

I'm looking to create interfaces that are strictly static-html and AJAX-based (meaning all the serverside processing occurs within servlets, not at initial-request-time or with forms).

It's great, and i love it, but i'm finding that i want to make the interface give more timely information to the user on the status of their request. Specifically, i want to have one request go out, the server to do multiple tasks in succession, and return a response after each task is done.

Before you ask, these successive tasks are reliant on one-another. They should all occur in sequence. It's not a matter of condensing different functions' responses into one request, it's a matter of giving realtime feedback to the user. The whole process can take up to a minute, and i'd prefer to give the user feedback during the process.

I also know that i could make some huge solution that saves progress data to an external source (like SQL or files) and have a separate getProgress() servlet which simply queries and returns that, but it's so bulky and unecessary, and adds so many dependencies for the sake of a little user feedback.

Is there any known, elegant way to receive multiple responses for a single AJAX request?

EDIT: clarified wording

Knetic
  • 2,099
  • 1
  • 20
  • 34
  • Do you really need multiple responses? As far as I know, that's impossible, but imho you could just send progress information to the client script as the action progresses in one response - the jquery script would not wait for the completion of the response, but instead would read data as they come. – kralyk Sep 21 '12 at 00:54
  • 2
    You're looking for "web sockets" http://www.html5rocks.com/en/tutorials/websockets/basics/ – Endophage Sep 21 '12 at 00:55
  • Although it is not possible with one request there are some options as long as your server can handle new requests while it is doing the work for example http://www.nickriggs.com/posts/simple-ajax-polling-plugin-for-jquery/ – Ryan Erickson Sep 21 '12 at 01:11
  • 1
    [See my answer to this question](http://stackoverflow.com/a/12486966/402706). The solution would fit your requirements as well. – Brandon Boone Sep 21 '12 at 02:40

0 Answers0