62,046
社区成员
发帖
与我相关
我的任务
分享
private int cur;
private int total;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Down"] == "C")
{
ThreadTest();
}
if (Request.QueryString["Down"] == "T")
{
ResponseProgress();
}
}
}
private void ThreadTest()
{
for (int i = 0; i < 5; i++)
{
this.cur = i+1;
this.total = 5;
Thread.Sleep(1000);
}
Response.Write("Complete!" + this.cur + "/" + this.total);
Response.End();
}
private void ResponseProgress()
{
Response.Buffer = true;
Response.Write(this.cur + "/" + this.total);
Response.Flush();
Response.End();
}
var xmlHttp;
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
xmlHttp = new XMLHTTPRequest();
}
function createRequest()//向服务器发出请求也就是向Default.aspx页面发出请求;
{
xmlHttp.onreadystatechange = DoResponse; //DoResponse是个回调函数
xmlHttp.open("GET", "AjaxDownload.aspx?Down=T", true);
xmlHttp.send(null);
}
function DoResponse()//服务器Default.aspx响应本页面并从服务器带回xmlHttp.responseText;
{
if (xmlHttp.readystate == 4 && xmlHttp.status == 200) {
document.getElementById("ResponseText").innerHTML = xmlHttp.responseText;
}
}
function clock() {
createRequest();
}
$(function() {
var clearflag;
$("#btn2").click(function() {
clearflag = self.setInterval("clock()", 500);
$.ajax({
type: "Get",
url: "AjaxDownload.aspx",
dataType: "text",
data: "Down=C",
success: function(data) {
window.clearInterval(clearflag);
alert(data);
}
});
}); //btn2 click end
}); //jq end
HTML的
<input type="button" id="btn2" value="AjaxThread" />