views:

34

answers:

1

I got a server-side script that I call with jQuery ajax method. It can take quite a while for it to process data set. After each row of input data is processed, it prints out a "OK <row id>" to output. The content type is plain/text.

What I want is to get this output in my jquery function, parse it as it comes and display some kind of feedback information to the user. As it can take up to 20-30 minutes to process all the data...

How can I do this in jQuery (the server script prints this out alredy). If I use the code below, I get the success function called after the script finishes its run.

$.ajax({
 type: "POST",
 url: "script.cgi",
 data: data,
 success: function() { 
   // do something
   alert ("OK");
 }
});
+1  A: 

You can't accomplish what you want with a single Ajax call. You will need some server-side interaction (storing the progress in a database or in the session) and then poll the server to get the status.

kgiannakakis
Oh, so I need to make 2 requests - one feeding the data, and one fetching state of processing, like every 10 seconds, to update the user's display? Makes me wonder why I can't process partial response from server in ajax call :(
kender
Yes that is what you need to do. Have also in mind that most browsers can't have many Ajax requests pending at the same time. An Ajax request would need to end before starting a new one. So it is never a good idea to have long standing Ajax requests.
kgiannakakis
Thanks for the explanation. :)
kender
I am glad, if I was able to help.
kgiannakakis