AJAX登陆

Posted on 2008-04-08 18:14  xiao zhou  阅读(1303)  评论(2)    收藏  举报
  最近,在学习 AJAX ,刚好也申请了博客园,刚好能把学习的历程,给记录下来 。

<script type="text/javascript">
    function Load()
    {
   
    var Name=document.getElementById("txtName").value;
    var pwd=document.getElementById("txtPwd" ).value;       
    WebApplication1.loading.GetLoad(Name,pwd,CallBackServer);
    document.getElementById("loading").style.display="block";   

    
     function CallBackServer(res)
   {
    var success=res.value;
    document.getElementById("loading").style.display="none";
  
    if(success)
    {
       document.getElementById("ss").innerHTML="登陆成功";
      
    }
     else
     {
      document.getElementById("ss").innerHTML="登陆失败";
    }
    }

   }
    </script>


<div>
        <input id="txtName" type="text" />
        <br />
        <br />
        <input id="txtPwd" type="text" /><br />
        <br />
        <br />
        <input id="btnLog" style="width: 51px" type="button" value="button" onclick="Load()" />
          </div>
       
        <div id="loading" style="display:none;">
        正在登陆中。。。。<br />
        </div>
            <br />
            <br />
            <div id="ss" style="width: 100px; height: 100px">
            </div>

后台代码:

protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(loading));

        }
        [AjaxPro.AjaxMethod]
        public bool GetLoad(string Name, string Pwd)
        {
            System.Threading.Thread.Sleep(3000);
            SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database=my51aspx");
            con.Open();
          string  mysql="select * from Member where Name='" + Name+ "' and Pass='" + Pwd+"'";
          SqlCommand cmd = new SqlCommand(mysql, con);
          SqlDataReader sdr = cmd.ExecuteReader();
          if (sdr.Read())
          {
              return true;
          }
          else
          {
              return false;
          }

        }



博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3