网站链接: 环球农商网
当前位置: 首页 > 资讯动态  > 平台资讯

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

2019/3/14 8:48:36 人评论

们要达到的目的是点击按钮,获得服务器的当前时间,aspx的html如下:
Html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Linkedu.Web.WebWWW.Default" %>

<!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" src="javascript/prototype/extras-array.js"></script>
   <script language="javascript" src="javascript/xmlHttp.js"></script>
   <script language="javascript" src="javascript/eventRouter.js"></script>
    <script language="javascript" src="Default.js"></script>
    <script language="javascript">
 
    </script>
</head>
<body>
    <form id="form1" runat="server">
        用Post方式获得服务器的当前时间
        <input id="btnTestPost" type="button" value="Post" />
        用Get方式获得服务器的当前时间
        <input id="btnTestGet" type="button" value="Get" />
        <div id="divResult"></div>
</form>
</body>
</html>

要用javascript 发送xmlHttp 请求必须解决的问题是跨浏览器的支持。我们把xmlHttp的发送封装在一个javascript对象中,同时在这个对象中解决了跨浏览器支持的问题。代码如下:

xmlHttp对象
/**//*
url-loading object and a request queue built on top of it
*/

/**//* namespacing object */
var net=new Object();

net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;


/**//*--- content loader object for cross-browser requests ---*/
net.xmlHttp=function(url, onload, params, method, contentType, onerror){
  this.req=null;
  this.onload=onload;
  this.onerror=(onerror) ? onerror : this.defaultError;
  if(typeof(method) == "undefined" || method == null)
  {
    method = "POST";
  }
  this.loadXMLDoc(url, params, method, contentType);
}

net.xmlHttp.prototype.loadXMLDoc=function(url, params, method, contentType){
  if (!method){
    method="GET";
  }
  if (!contentType && method=="POST"){
    contentType='application/x-www-form-urlencoded';
  }
  if (window.XmlHttpRequest){
    this.req=new XmlHttpRequest();
  } else if (window.ActiveXObject){
    this.req=new ActiveXObject("Microsoft.xmlHttp");
  }
  if (this.req){
    try{
      var loader=this;
      this.req.onreadystatechange=function(){
        net.xmlHttp.onReadyState.call(loader);
      }
      this.req.open(method,url,true);
    &nb

相关资讯

  • document.cookie:客户端操作cookie

    我们已经知道,在 document 对象中有一个 cookie 属性。但是 Cookie 又是什么?&ldquo;某些 Web 站点在您的硬盘上用很小的文本文件存储了一些信息,这些文件就称为 Cookie。&rdquo;&mdash;&mdash; MSIE 帮助。一般来说,Cookies 是 CGI 或类似,比 HTML …

    2019/4/12 8:18:11
  • 用ASP实现分级权限控制

    本文实现的是一个帐务管理系统中分级权限的控制,程序使用ASP和JavaScript编写,在装有IIS4.0的win NT服务器上运行,速度快,易维护。  权限级别划分如下:  ①、院长和财务科长:不能输入,可以无限制查询、统计;  ②、副院长:不能输入,可以查询、统计其分管部…

    2019/4/12 8:18:11
  • ASP实现Rewrite模拟生成静态页效

    以前刚刚懂404.asp的时候,曾经幻想把所有程序代码写到404.asp中,实现一个模拟生成静态网页的站,如果程序小还可以,用404.asp实现Rewrite还是一个不错的选择,如果程序代码多达100000行,恐怕就要开始爬了  直到看到asp的Server.Transfer,用404模拟生成静态页的站的念…

    2019/4/12 8:18:11
  • ASP随机涵数生成100条8位字母和数字混合密码

    <%for i = 1 to 100%><%Randomizepass=""Do While Len(pass)<8 随机密码位数num1=CStr(Chr((57-48)*rnd+48)) 0~9num2=CStr(Chr((122-97)*rnd+97)) a~zpass=pass&num1&num2loop原创:www.devdao.com%><%=pass%><br><%next…

    2019/4/12 8:18:11

共有条评论 网友评论

验证码: 看不清楚?