Q:

AJAX / ASP - Update Progress Panel - Response.Flush

I am currently learning AJAX for the first time, mixed with Classic ASP.
I have an AJAX script, that calls my ASP page (process.asp). In the ASP file is a simple loop between 1 and 1000, which is portraying an image process that I have elsewhere in my site, which I would like to add AJAX to later.
AJAX SCRIPT
function processItems()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("notification").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","processItems.asp",true);
xmlhttp.send();
}

ASP PAGE
Response.Expires = -1
i = 0
Do Until i = 1000
i = i + 1
Loop
Response.Write "Process complete"

At the moment it works fine, when the process has finished it writes a message to the user "process complete"... but, because there are lots of items to process, I would like to inform my user which item is currently getting processed e.g. "processing item 17 of 1000".
I've read that I need 'Response.Flush' to perform this task, so...
Can I use '.flush' in the loop part of my ASP script, to display the item number (i)? If yes, do I need anything else? If no, can somebody explain what I'll need to do to get it working?
This is what I was thinking:
Response.Buffer = True
Response.Expires = -1
i = 0
total = 1000
Do Until i = total
i = i + 1
Response.Write "Processing Item "&i&" of "&total&""
Response.Flush
Loop

Many thanks in advance

A:

Its not possible to get where you want. Your ajax call will return a response once its complete, if you have 10000 files to process, you will get a response after the processing end in the last file.
You can change your aproach, by using REVERSE AJAX (commet ajax) or, using the same technology, I suggest you the following:

one ajax call to get how many files need processing.
one ajax call to process a file based on a index.

