mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. DotNET
  3. Main content

ajax处理耗时事件,显示loading的方法

2012-02-24 83hotness 0likes 0comments

<%@ 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

Tag: Nothing
Last updated:2012-02-24

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang