C# Ajax为什么我的刷新不能成功,高手看看

这是源码:帮我看看

 

Ajax.aspx 页面

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="Ajax" %>

<!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">
       
        function Execute()
        {
            Http_Request=false;     //声明XMLHttpRequest
          
           
            //初始化XMLHttpRequest
            if(window.XMLHttpRequest)
            {
                //非IE浏览器
                Http_Request=new XMLHttpRequest();
            }else if(window.ActiveXObject){
                  
                    try
                    {
                     /// alert("IE新版本");
                      Http_Request=new ActiveXObject("msxml2.XMLHTTP");    //IE新版本
                        
                    }catch(e){
                        try
                        {
                        // alert("IE旧版本");
                         Http_Request=new ActiveXObject("microsoft.XMLHTTP");    //IE旧版本
                        
                        }catch(e){ }
                    }
            }else{
                alert("不能创建XMLHttpReques对象,无法应用Ajax");
                return false;
            }
           
            // 指定回调函数
          Http_Request.onReadyStateChange=login;
            alert("“指定回调函数”也执行了的");
          //创建Http请求
          Http_Request.Open("get","Handler.ashx?txtLogin="+document.getElementById("txtLogin").value,true);
         
         //发送Http请求
         Http_Request.send(null);
       
        }
   
            function login()
            {  
              
                if(Http_Request.readyState==4)    //是否发送成功
                {
                    if(Http_Request.status==200)    //是否交易成功
                    {
                        //正式开始处理数据
                        document.getElementById("lblMessage").innerText=Http_Request.responseText;
                    }
                }
            }
    </script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
             <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 140px; position: relative;
                top: 108px" Text="账号:"></asp:Label>
            <asp:TextBox ID="txtLogin" runat="server" onBlur="Execute()" Style="z-index: 101; left: 192px; position: relative;
                top: 104px" AutoCompleteType="Disabled"></asp:TextBox>
            <asp:TextBox ID="txtPass" runat="server" Style="z-index: 102; left: 36px; position: relative;
                top: 176px" AutoCompleteType="Disabled"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Style="z-index: 103; left: -226px; position: relative;
                top: 176px" Text="密码:"></asp:Label>
            <asp:Button ID="btnSubmit" runat="server" Style="z-index: 104; left: 296px; position: absolute;
                top: 280px" Text="提交" />
            <asp:Label ID="lblMessage" runat="server" Style="z-index: 106; left: 8px; position: relative;
                top: 104px"></asp:Label>
    </div>
    </form>
</body>
</html>

 

 

 

 

Handler.ashx 页面

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string login = context.Request.QueryString["txtLogin"].ToString(); 
       
        int num = 1;
        if (num > 0)
        {
            context.Response.Write("该用户已经存在!");
        }
        else
        {
            context.Response.Write("可以是用[" + login + "]");

        }
       
       
        context.Response.Write("Hello World");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值