I am currently delving into the realm of AJAX alongside Classic ASP for the very first time.
Within my AJAX script, I'm calling an ASP page (process.asp) that contains a simple loop iterating from 1 to 1000. This loop mimics an image processing task on my website, which I plan to enhance with AJAX in the future.
MY 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();
}
THE ASP PAGE
Response.Expires = -1
i = 0
Do Until i = 1000
i = i + 1
Loop
Response.Write "Process complete"
While the current setup works well and displays a "process complete" message upon finishing, I aim to update it to show the user which item is being processed at any given moment e.g., "processing item 17 of 1000".
Research suggests that I need 'Response.Flush' for this purpose, so...
Can I utilize '.flush' within the loop section of my ASP script to output the item number (i)? If so, are there any additional requirements? If not, could someone guide me on what steps I should take to achieve this functionality?
This is my proposed solution:
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
Your assistance is greatly appreciated.