rt

解决方案 »

  1.   

    <script type="text/javascript">   
      var xmlHttp;   
      function createXMLHttpRequest()   
      {   
      if(window.ActiveXObject)   
      {   
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
      }   
      else if(window.XMLHttpRequest)   
      {   
      xmlHttp = new XMLHttpRequest();   
      }   
      }   
      function CheckUserName()   
      {   
      var us=document.getElementById("txtname").value;   
      if(us!="")   
      {   
      createXMLHttpRequest();   
      var url= "RegistValidate.ashx?username="+escape(document.getElementById("txtname").value);   
      xmlHttp.open("GET",url,true);   
      xmlHttp.onreadystatechange=ShowResult;   
      xmlHttp.send(null);   
      }   
      }   
      function ShowResult()   
      {   
      if(xmlHttp.readyState==4)   
      {   
      if(xmlHttp.status==200)   
      {   
      var s;   
      s=xmlHttp.responseText;   
      alert(s);   
      }   
      }   
      }   
    </script>   
    public void ProcessRequest(HttpContext context) 
        { 
      string username = this.Request.QueryString["username "];
        if(查询)
           context.Response.Write("1");
         else
           context.Response.Write("0");
       
        } 
      

  2.   

    用jQuery更方便
    public class KmbHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            
            context.Response.ContentType = "text/plain";
            MyConn myConn = new MyConn();
            DataTable dt = new DataTable();
            dt = myConn.getDataTable("Select Dm,Dmm From kmb Order by Dm");
            string Data = "<table>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Data += "<tr><td>" + dt.Rows[i]["Dm"].ToString().Trim() + "</td><td>" + dt.Rows[i]["Dmm"].ToString() + "</td></tr>";            
            }
            Data += "</table>";
            context.Response.Write(Data);
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    js
    $(function(){
       $.post("KmbHandler.ashx",{"type":"0"},function(data){
        $("#Kmb").append(data);
       });
    })
      

  3.   


    $.ajax({
      url:"xx.ashx",
      type:"post",
      data:"UserName="+$("#username").val()+"&password="+$("#password").val()+"",
      beforeSend:function(){},
      success:function(result){
          //增删改查成功后返回
           if(result=="true")
           alert("操作成功");
      },
      error:function(resMsg){alert(resMsg)}
    })
    xx.ashx
    获取username,password值
    public class KmbHandler : IHttpHandler {
        
      public void ProcessRequest (HttpContext context) {
      context.Response.ContentType = "text/plain";
      string username = Request.Form["UserName"].ToString();
      string pass = Request.Form["Password"].ToString();
      //之后插入
      }
      
      public bool IsReusable {
      get {
      return false;
      }
      }//修改删除差不多,获取传过来的值在进行操作!
      

  4.   

    回复 3#:
     "text/plain" ?这个是什么啊
      resMsg ?这个用不用赋值
      

  5.   

    text/plain是无格式正文,
    resMsg是返回错误,不用赋值,如果错误他会直接弹出!
      

  6.   

    wuyq11
     
    (人生如梦)正解代码都给你了Jquery我不是说不好,毕竟不是源生态,有点大。编译调试 5万多行代码看个人了Jquery封装了使用的确简单了很多.....
      

  7.   

    写在xx.ashx里面
    里面不是获得用户名和密码了吗(那个是举例)
    然后你进行要操作的方法就可以!
      

  8.   

    jquery的ajax的一个例子:
    http://www.cnblogs.com/chenping-987123/archive/2010/08/27/1809877.html
      

  9.   

    的确是的所以说看个人了ajax的实现过程Jquery都封装了,不过我个人还是和
    wuyq11
     
    (人生如梦)
    比较搭调
      

  10.   

    http://blog.csdn.net/porschev/archive/2010/10/15/5943579.aspx#FeedBack
      

  11.   

    使用jquery的$.ajax方法 返回数据即可
      

  12.   

    xx.ashx 里面  不存在Request对象