1

In long server processes, server can progressively write responses, like:

Copying 100 files completed,

after 10 seconds:

Archiving files completed,

after 30 seconds:

Deleting temporary files completed,

and ....

Is it possible to fetch this stream before the ajax is completed and show it to the user?

EBAG
  • 18,548
  • 12
  • 51
  • 89

3 Answers3

3

Sounds like you're looking for long polling. You also might want to read about the Comet pattern. I also just answered a question a few minutes ago that touches on similar issues.

Community
  • 1
  • 1
Ken Redler
  • 22,899
  • 7
  • 55
  • 68
0

You can use two async callbacks .. One to carry out the processing (delete files or whatever) that keeps the value of a session variable updated (the number of files deleted). The other async callback can check the value of this session variable on a set timeout period and then update the GUI accordingly,

bleeeah
  • 3,306
  • 17
  • 25
0

Fetching it as one call would probably be useless even if you set the timeout high enough to capture all as the use will not get any feedback until its finished.

Going with multiple status polls is the only way to go.

But depending on how your server runs there might be some quirks to think of.

For example, IIS uses only one thread per session, so two simultaneous calls from the same client will be handled after each other.

If you have posted something with ajax or iframe that takes time to process, like a file upload, then that call will block the session and any status page need to be sessionless to be able to respond directly.

David MÃ¥rtensson
  • 7,235
  • 4
  • 28
  • 47