52,797
社区成员
发帖
与我相关
我的任务
分享
public class test : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
for (int i = 0; i < 5; i++)
{
context.Response.Write(i);
context.Response.Flush();
System.Threading.Thread.Sleep(5000);
}
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery.js">
</script>
<script type="text/javascript">
var xmlhttp;
$(document).ready(function() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "../ajax/test.ashx", true);
xmlhttp.send();
setInterval(function() {
$("#content").text(xmlhttp.responseText);
//不能使用xmlhttp.responseText = "";,属性只读
}, 1000);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
</div>
</form>
</body>
</html>