<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="WebApplication1.WebForm5" %>
<!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 language="javascript" type="text/javascript">
var xmlHttp;
//xmlHttpRequest
function createXMLHttpRequest()
{
if (window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE
else if (window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest(); //Firefox
}
function htmer_loading()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange = function ()
{
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
//若响应完成,则显示htmer.asp中的内容
document.getElementById("show").innerHTML = xmlHttp.responseText;
else
//若响应未完成,则显示Loading
document.getElementById("show").innerHTML = "Loading......";
}
xmlHttp.open("GET", "Handler1.ashx", true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="check ajax" onclick="htmer_loading()" />
</div>
<div id="show">
</div>
</form>
</body>
</html>
耗时请求页面处理Handler1.ashx
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Thread.Sleep(3000);
context.Response.Write("<Br/> test result");
context