当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  用.net 处理xmlHttp发送异步请求 2

 用.net 处理xmlHttp发送异步请求 2

点击次数:17 次 发布日期:2008-11-26 11:32:12 作者:源代码网
源代码网推荐      下面开始写发送xmlHttp请求的代码:
源代码网推荐  
源代码网推荐  default.js
源代码网推荐  //全局xmlHttp对象
源代码网推荐  var cobj;
源代码网推荐  
源代码网推荐  /**//* Post begin*/
源代码网推荐  //绑定Post发送xmlHttp事件到btnTestPost
源代码网推荐  function loadTestPost()
源代码网推荐  {
源代码网推荐   var iobj = document.getElementById("btnTestPost");
源代码网推荐   //btnTestPost按钮监听的绑定
源代码网推荐   var clickRouter=new jsEvent.EventRouter(iobj,"onclick");
源代码网推荐   clickRouter.addListener(btnTestPostClick);
源代码网推荐  }
源代码网推荐  function btnTestPostClick()
源代码网推荐  { // open参数 url, onload, params, method, contentType, onerror
源代码网推荐   cobj = new net.xmlHttp("DefaultHandler.ashx",dealResult, "<T/>", "POST");
源代码网推荐  }
源代码网推荐  /**//* Post end*/
源代码网推荐  
源代码网推荐  
源代码网推荐  /**//* Get begin*/
源代码网推荐  //绑定Get发送xmlHttp事件到btnTestGet
源代码网推荐  function loadTestGet()
源代码网推荐  {
源代码网推荐   var iobj = document.getElementById("btnTestGet");
源代码网推荐   //btnTestGet按钮监听的绑定
源代码网推荐   var clickRouter=new jsEvent.EventRouter(iobj,"onclick");
源代码网推荐   clickRouter.addListener(btnTestGetClick);
源代码网推荐  }
源代码网推荐  function btnTestGetClick()
源代码网推荐  { // open参数 url, onload, params, method, contentType, onerror
源代码网推荐   cobj = new net.xmlHttp("DefaultHandler.ashx?T=1",dealResult, null, "GET");
源代码网推荐  }
源代码网推荐  /**//* Get end*/
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  function dealResult()
源代码网推荐  {
源代码网推荐   var dobj = document.getElementById("divResult");
源代码网推荐   dobj.innerHTML = cobj.req.responseXML.text;
源代码网推荐  }
源代码网推荐  
源代码网推荐  
源代码网推荐  window.onload = function()
源代码网推荐  {
源代码网推荐   //绑定Post发送xmlHttp事件到btnTestPost
源代码网推荐   loadTestPost();
源代码网推荐   //绑定Get发送xmlHttp事件到btnTestGet
源代码网推荐   loadTestGet();
源代码网推荐  };
源代码网推荐  
源代码网推荐  最后是.net处理xmlHttp的代码
源代码网推荐  .net 处理xmlHttp请求
源代码网推荐  public class DefaultHandler : IHttpHandler
源代码网推荐   {
源代码网推荐   protected XmlDocument _xmlResult;
源代码网推荐  
源代码网推荐   public void ProcessRequest(HttpContext context)
源代码网推荐   {
源代码网推荐   if (context.Request["T"] != null)
源代码网推荐   {//GET xmlhttp测试
源代码网推荐   context.Response.ContentType = "text/xml";
源代码网推荐   XmlDocument xmlDoc = new XmlDocument();
源代码网推荐   xmlDoc.LoadXml(string.Format(@"<time>GET:{0}</time>", System.DateTime.Now));
源代码网推荐   xmlDoc.Save(context.Response.OutputStream);
源代码网推荐   context.Response.End();
源代码网推荐   }
源代码网推荐   else
源代码网推荐   {//POST xmlhttp测试
源代码网推荐   context.Response.ContentType = "text/xml";
源代码网推荐   XmlDocument xmlDoc = new XmlDocument();
源代码网推荐   xmlDoc.Load(context.Request.InputStream);
源代码网推荐   if (xmlDoc.DocumentElement.Name == "T")
源代码网推荐   {
源代码网推荐   xmlDoc.LoadXml(string.Format(@"<time>POST:{0}</time>", System.DateTime.Now));
源代码网推荐   xmlDoc.Save(context.Response.OutputStream);
源代码网推荐   context.Response.End();
源代码网推荐   }
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   public bool IsReusable
源代码网推荐   {
源代码网推荐   get
源代码网推荐   {
源代码网推荐   return false;
源代码网推荐   }
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/Files/laiwen/XmlHttpNet.rar
源代码网推荐  http://www.cnblogs.com/laiwen/archive/2006/12/26/604050.html
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华