AJAX/ASP-更新进度面板-Response.Flush [英] AJAX / ASP - Update Progress Panel - Response.Flush

查看:159
本文介绍了AJAX/ASP-更新进度面板-Response.Flush的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前是第一次将AJAX与Classic ASP混合使用.

I am currently learning AJAX for the first time, mixed with Classic ASP.

我有一个AJAX脚本,该脚本调用了我的ASP页(process.asp).在ASP文件中,是一个介于1到1000之间的简单循环,该循环描绘了​​我在站点其他地方拥有的图像处理过程,我想在以后添加AJAX.

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脚本

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页

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

目前工作正常,当过程完成时,它会向用户过程已完成"写入一条消息...但是,由于有很多项目要处理,因此我想通知用户哪个项目是当前正在处理中,例如处理第17项,共1000项".

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".

我已经读到我需要'Response.Flush'来执行此任务,所以...

I've read that I need 'Response.Flush' to perform this task, so...

我可以在ASP脚本的循环部分中使用".flush"来显示项目编号(i)吗?如果是,我还需要其他东西吗?如果没有,有人可以解释一下我需要做些什么才能使其正常工作吗?

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?

这就是我的想法:

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

非常感谢

推荐答案

无法到达您想要的位置.您的ajax调用完成后将返回响应,如果您要处理10000个文件,则在处理结束后将在最后一个文件中得到响应.

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.

您可以通过使用REVERSE AJAX(commet ajax)或使用相同的技术来更改方法,我建议您执行以下操作:

You can change your aproach, by using REVERSE AJAX (commet ajax) or, using the same technology, I suggest you the following:

  1. 一个ajax调用以获取需要处理的文件数.
  2. 一个ajax调用以基于索引处理文件.

这篇关于AJAX/ASP-更新进度面板-Response.Flush的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆