我的AjaxXmlHttp

 1// JScript 文件
 2
 3 function AjaxXmlHttp(url)
 4    {
 5        var xmlhttp;
 6                try
 7                {   
 8                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 9                }

10                catch(e)
11                {
12                   try
13                   {
14                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
15                   }

16                   catch(e)
17                   {
18                        try
19                        {
20                        }

21                        catch(e)
22                        {
23                            xmlhttp = new XMLHttpRequest();
24                        }

25                   }

26                }

27                
28                 xmlhttp.onreadystatechange = function()
29                 {         
30                   if(xmlhttp.readystate==4)
31                    {                  
32                        
33                         if(xmlhttp.status == 200)
34                         {
35                            
36                           alert(xmlhttp.ResponseText);                       
37                         }

38                         else
39                         {
40                            alert("读取数据出错,错误端口号是:"+xmlhttp.status);
41                         }

42                    }

43               }
           
44              xmlhttp.open("get",url,true);
45              xmlhttp.send(null);              
46    }
二、处理xmlhttp
HTML
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Active.aspx.cs" Inherits="Ajax_Active" %>
多余的html代码应除掉。

CS
 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Collections;
 5using System.Web;
 6using System.Web.Security;
 7using System.Web.UI;
 8using System.Web.UI.WebControls;
 9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Ajax_Active : System.Web.UI.Page
13{
14    protected void Page_Load(object sender, EventArgs e)
15    {
16
17        string id = Request["id"].ToString();
18        string flag = Request["flag"].ToString();
19        if (flag == "no")
20        {
21            string sql = "update userinfo set isactivate='0' where userid='" + id + "'";
22            DAL.SQLHelper.ExecuteNonQuery(DAL.SQLHelper.CONN_STRING, CommandType.Text, sql, null);
23            Response.Write("取消激活成功");
24        }

25        else if (flag == "yes")
26        {
27            string sql = "update userinfo set isactivate='1' where userid='" + id + "'";
28            DAL.SQLHelper.ExecuteNonQuery(DAL.SQLHelper.CONN_STRING, CommandType.Text, sql, null);
29            Response.Write("激活成功");
30        }

31        
32    }

33}
三、调用
 1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyUsers.aspx.cs" Inherits="u_MyUsers" %>
 2
 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4<html xmlns="http://www.w3.org/1999/xhtml">
 5<head runat="server">
 6    <title>无标题页</title>
 7    <link href="StyleSheet.css" type="text/css" rel="Stylesheet" />
 8
 9    <script src="../Js/AjaxXmlHttp.js" language="javascript"></script>
10
11</head>
12<body>
13    <form id="form1" runat="server">
14        <div>
15            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
16                <Columns>
17                    <asp:BoundField HeaderText="会员编号" DataField="username" />
18                    <asp:BoundField HeaderText="昵称" DataField="nickname" />
19                    <asp:BoundField HeaderText="姓名" DataField="realname" />
20                    <asp:BoundField HeaderText="手机号" DataField="mobile" />
21                    <asp:BoundField HeaderText="QQ号" DataField="qq" />
22                    <asp:BoundField HeaderText="E-mail" DataField="email" />
23                    <asp:TemplateField HeaderText="状态">
24                        <ItemTemplate>
25                            <%#IsActive(Eval("isactivate").ToString())%>
26                        </ItemTemplate>
27                    </asp:TemplateField>
28                    <asp:TemplateField HeaderText="操作">
29                        <ItemTemplate>
30                            <href="#" onclick="AjaxXmlHttp('../Ajax/Active.aspx?id=<%#Eval("userid") %>&flag=yes');ReLoad();">
31                                激活</a> <href="#" onclick="AjaxXmlHttp('../Ajax/Active.aspx?id=<%#Eval("userid") %>&flag=no');ReLoad();">
32                                    取消激活</a>
33                        </ItemTemplate>
34                    </asp:TemplateField>
35                </Columns>
36            </asp:GridView>
37        </div>
38    </form>
39</body>
40</html>

posted @ 2008-04-10 22:56  yellowwood  阅读(285)  评论(0编辑  收藏  举报
Never Give UP