/** * Ajax对象 * function functionName(reAjax,status){if(status == 200)alert(reAjax.responseText);} * * 例:1:GET * var myAjax=new Ajax(); * myAjax.open("http://www.ttzx.com:88/ajax/re.php",functionName); * myAjax.send(); * * 例:2:POST * var myAjax=new Ajax(); * myAjax.open("http://www.ttzx.com:88/ajax/re.php",functionName); * myAjax.send("sendType=Post&sendValue=myDatas"); */ function Ajax(){ /** * 初始化一个xmlhttp对象 */ this.newAjax=function(){ var name=false; try{    name = new ActiveXObject("Msxml2.XMLHTTP");   } catch (e) {     try {      name = new ActiveXObject("Microsoft.XMLHTTP");    } catch (e) {   if (typeof XMLHttpRequest!='undefined') {     try {     name = new XMLHttpRequest(); } catch (e) { if (window.createRequest){ try{ name=window.createRequest(); } catch (e) { name=false; } }   }     }   } } return name; } var backthis=this;//备份Ajax对象实例 this.call=function() { //如果执行是状态正常,那么就把返回的内容赋值给上面指定的层 if (backthis.Ajax.readyState == 4){ backthis.setReFunction(backthis.Ajax,backthis.Ajax.status); } } /** * xmlhttp对象的send方法 */ this.send=function(value){ if (typeof(this.url) == 'undefined'){ return false; }   if (typeof(this.call) == 'undefined'){ return false; } if(typeof(value)=='undefined'){//使用Get方式进行请求 if(typeof(this.userName) =='undefined') this.Ajax.open("GET",this.url,this.varAsync); else this.Ajax.open("GET",this.url,this.varAsync,this.userName,this.passWord); this.Ajax.onreadystatechange = this.call;//设置执行状态回调处理函数句柄 this.Ajax.send(null);//发送 } else{ //使用POST方式进行请求 if(typeof(this.userName) =='undefined') this.Ajax.open("POST",this.url,this.varAsync); else this.Ajax.open("POST",this.url,this.varAsync,this.userName,this.passWord); this.Ajax.onreadystatechange = this.call;//设置执行状态回调处理函数句柄 this.Ajax.setRequestHeader("Content-Length",value.length); this.Ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded"); this.Ajax.send(value);//发送 } } /** * AJAX对象的OPEN方法:取消发送 */ this.open=function(url,reFunction){ if (typeof(url) == 'undefined'){ return false; } this.url=url; if (typeof(reFunction) != 'undefined'){ this.setReFunction= reFunction; } } /** * xmlhttp对象的resend方法:取消发送 */ this.close=function(){ this.Ajax.abort(); } this.userName; //如果服务器需要验证,此处指定用户名. this.passWord; //验证信息中的密码部分. this.url; //请求的URL地址,可以为绝对地址也可以为相对地址. this.varAsync=true; //布尔型,指定此请求是否为异步方式,默认为true. this.setReFunction=function(reAjax,status){alert(status)}; //操作成功后要调用的用户自定义函数. this.Ajax=this.newAjax(); } var myAjax=new Ajax(); function sendcount(channelid,title,url){ myAjax.open("/selfdo/sendcount.php?channelid="+channelid+"&url="+encodeURIComponent(url),resendcount); myAjax.send("&title="+title); } function resendcount(reAjax,status){}