tags:

views:

112

answers:

1

i would like to send responses to the client during an ajax request (imagine a file upload or something) and react on that responses on the clientside.

  1. send ajax request
  2. do lot of work on serverside and send information about that to the clientside
  3. during the serverside ist still doing lot of work do something on clientside like inform user about progress...

i hope this is understandable?

now how to do that? until now i am only able to react when the ajax request is complete.

+1  A: 

You might try using multiple ajax requests and calling them sequentially using whatever callback facility is offered by the framework you're using. For example (jQuery):

function getData(){
    $.load(someUrl,onDataReceived)
}
function getMoreData(){
    $.load(someOtherUrl,onMoreDataReceived);
}
function onDataReceived(){
    // update your UI in a meaningful way so that the user knows things are happening
    getMoreData();
}
function onMoreDataReceived(){
    // update your UI again
    alert('Got Everything');
}
$(function(){ getData(); }); // start the process on page load

I believe it's possible to listen for "progress events", but I think those are limited to things like file uploads, etc.

Anyway, good luck!

inkedmn
You might want to put getMoreData in a settimeout block otherwise it will be polling too often.
Byron Whitlock