Ajax类

var Ajax={

    sendstr:"",

    sendurl:"",

    loading:"loading...",

    method:"POST",

    contentid:"",

    loadingid:"",

    CreateXMLHttpRequest:function() {

         var request = false;

         if(window.XMLHttpRequest) {

              request = new XMLHttpRequest();

              if(request.overrideMimeType) {

                   request.overrideMimeType('text/xml');

              }

         } else if(window.ActiveXObject) {

              var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];

              for(var i=0; i<versions.length; i++) {

                   try {

                       request = new ActiveXObject(versions[i]);

                       if(request) {

                            return request;

                       }

                   } catch(e) {}

              }

         }

         return request;

     },

   

    getElement:function(EID) {

        return (document.getElementById) ? document.getElementById(EID): document.all[EID];

    },

    ajccache:new Object(),

    send:function() {

        var XMLHttpRequest=Ajax.CreateXMLHttpRequest();

         var ocontent=Ajax.getElement(Ajax.contentid);

         var Cocontent=Ajax.getElement(Ajax.loadingid);

        if(Ajax.ajccache[Ajax.sendurl]==null) {

             XMLHttpRequest.onreadystatechange=function(){

                 if(XMLHttpRequest.readyState == 4 && (XMLHttpRequest.status==200 || window.location.href.indexOf("http")==-1)) {                     

                      ocontent.innerHTML=XMLHttpRequest.responseText;

                      Ajax.ajccache[Ajax.sendurl]=ocontent.innerHTML;

                     } else {

                     Cocontent.innerHTML=Ajax.loading;

                 }

             }

             if(Ajax.method.toUpperCase()=="POST") {

                   XMLHttpRequest.open("POST",Ajax.sendurl,true);

                   XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                   XMLHttpRequest.send(Ajax.sendstr);

            }

            else {

                   XMLHttpRequest.open("GET",Ajax.sendurl,true);

                   XMLHttpRequest.send(null);

            }

        }else{

            ocontent.innerHTML=Ajax.ajccache[Ajax.sendurl];

        }

    }

}

 

调用

             Ajax.sendurl="d.php?authnum="+Math.random();

             Ajax.method="post";

             Ajax.contentid="Err";

             Ajax.loadingid="Err";

             Ajax.loading='数据加载中,请稍候...'

             Ajax.sendstr="type="+type+"&SEC="+document.getElementById(pp).value;

             Ajax.send();

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值