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();

 

posted on 2008-07-14 16:04  wkjs  阅读(163)  评论(0编辑  收藏  举报