日期:2014-05-16 浏览次数:20718 次
<form id="frmbox" method="post" action="/ajaxaction.php"></form>
function AjaxSubmit() { var ajax = new AJAXRequest(); ajax.postf("frmbox", Callback); } function Callback(obj) { var a = obj.responseText; result = 0; if (!isNaN(a)) result = parseInt(a); } function AJAXRequest() { var xmlPool=[],objPool=[],AJAX=this,ac=arguments.length,av=arguments; var xmlVersion=["MSXML2.XMLHTTP","Microsoft.XMLHTTP"]; var ec=emptyFun=function(){}; av=ac>0?typeof(av[0])=="object"?av[0]:{}:{}; var encode=$GEC(av.charset+""); var prop=['url','content','method','async','timeout','ontimeout','onrequeststart','onrequestend','oncomplete','onexception']; var defval=['','','GET',true,3600000,ec,ec,ec,ec,ec],l=prop.length; while(l--){this[prop[l]]=getp(av[prop[l]],defval[l]);} if(!getObj()) return false; function getp(p,d) { return p!=undefined?p:d; } function getObj() { var i,j,tmpObj; for(i=0,j=xmlPool.length;i<j;i++) if(xmlPool[i].readyState==0||xmlPool[i].readyState==4) return xmlPool[i]; try { tmpObj=new XMLHttpRequest; } catch(e) { for(i=0,j=xmlVersion.length;i<j;i++) { try { tmpObj=new ActiveXObject(xmlVersion[i]); } catch(e2) { continue; } break; } } if(!tmpObj) return false; else { xmlPool[xmlPool.length]=tmpObj; return xmlPool[xmlPool.length-1]; } } function $(id){return document.getElementById(id);} function $N(d){var n=d*1;return(isNaN(n)?0:n);} function $VO(v){return(typeof(v)=="string"?(v=$(v))?v:false:v);} function $GID(){return((new Date)*1);} function $SOP(id,ct){objPool[id+""]=ct;} function $LOP(id){return(objPool[id+""]);} function $SRP(f,r,p){return(function(s){s=f(s);for(var i=0;i<r.length;i++) s=s.replace(r[i],p[i]);return(s);});} function $GEC(cs){ if(cs.toUpperCase()=="UTF-8") return(encodeURIComponent); else return($SRP(escape,[/\+/g],["%2B"])); } function $ST(obj,text) { var nn=obj.nodeName.toUpperCase(); if("INPUT|TEXTAREA|OPTION".indexOf(nn)>-1) obj.value=text; else try{obj.innerHTML=text;} catch(e){}; } function $CB(cb) { if(typeof(cb)=="function") return cb; else { cb=$VO(cb); if(cb) return(function(obj){$ST(cb,obj.responseText);}); else return this.oncomplete; } } function $GP(p,v,d,f) { var i=0; while(i<v.length){p[i]=v[i]?f[i]?f[i](v[i]):v[i]:d[i];i++;} while(i<d.length){p[i]=d[i];i++;} } function send(purl,pc,pcbf,pm,pa) { var ct,ctf=false,xmlObj=getObj(),ac=arguments.length,av=arguments; if(!xmlObj) return false; var pmp=pm.toUpperCase()=="POST"?true:false; if(!pm||!purl) return false; var ev={url:purl, content:pc, method:pm}; purl+=(purl.indexOf("?")>-1?"&":"?")+"timestamp="+$GID(); xmlObj.open(pm,purl,pa); AJAX.onrequeststart(ev); if(pmp) xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); ct=setTimeout(function(){ctf=true;xmlObj.abort();},AJAX.timeout); var rc=function() { if(ctf) { AJAX.ontimeout(ev); AJAX.onrequestend(ev);