利用Ajax检测帐户是否存在

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

为不刷新页面,检测输入的用户名是否已经注册,示例如下:1.脚本如下:viewplaincopytoclipboardprint?1.*AJAXRequest类2.3.*@authorxujiwei4.5.*@constructor6.7.*@classAJAXRequest8.9.*@param{Object}[initObj]初始化参数对象10.11.*@param{String}[initObj.url=]要请求的Url12.13.*@param{String}[initObj.content=]要发送的内容14.15.*@param{String}[initObj.method=GET]请求方法,GET或16.17.18.19.POST20.21.*@param{String}[initObj.charset]发送数据时使22.23.24.25.用的编码26.27.*@param{Boolean}[initObj.async=true]请求类型,true为异28.29.30.31.步,false为同步32.33.*@param{Number}[initObj.timeout=3600000]请求超时时间,单位为34.35.36.37.毫秒38.39.*@param{function}[initObj.ontimeout]请求超时时的40.41.42.43.回调函数44.45.*@param{function}[initObj.onrequeststart]请求开始时的46.47.48.49.回调函数50.51.*@param{function}[initObj.onrequestend]请求结束时的回调函数52.53.*@param{function}[initObj.oncomplete]请求正确完成时的回调54.55.56.57.函数58.59.*@param{function}[initObj.onexception]请求发生异常时的回调60.61.62.63.函数64.65.*@property{String}url要请求的Url66.67.*@property{String}content要发送的内容68.69.*@property{String}method请求方法,GET或POST70.71.*@property{String}charset发送数据时使用的编码72.73.*@property{Boolean}async请求类型,true为异步,false为同步74.75.*@property{Number}timeout请求超时时间,单位为毫秒76.77.*@property{function}ontimeout请求超时时的回调函数78.79.*@property{function}onrequeststart请求开始时的回调函数80.81.*@property{function}onrequestend请求结束时的回调函数82.83.*@property{function}oncomplete请求正确完成时的回调函数84.85.*@property{function}onexception请求发生异常时的回调函数86.87.*@example88.89.*varajax1=newAJAXRequest();90.91.*varajax2=newAJAXRequest({92.93.*url:getdata.asp,//从getdata.asp获取数据94.95.*method:GET,//GET方式96.97.*oncomplete:function(obj){98.99.*alert(obj.responesText);//显示getdata.asp输出的内容100.101.*});102.103.*/104.105.functionAJAXRequest(){106.107.varxmlPool=[],objPool=[],AJAX=this,ac=arguments.length,av=arguments;108.109.varxmlVersion=[MSXML2.XMLHTTP,Microsoft.XMLHTTP];110.111.varec=emptyFun=function(){};112.113.av=ac0?typeof(av[0])==object?av[0]:{}:{};114.115.varencode=$GEC(av.charset+);116.117.varprop=118.119.120.121.['url','content','method','async','timeout','ontimeout','onrequeststart','onrequestend','onc122.123.124.125.omplete','onexception'];126.127.vardefval=['','','GET',true,3600000,ec,ec,ec,ec,ec],l=prop.length;128.129.while(l--){this[prop[l]]=getp(av[prop[l]],defval[l]);}130.131.if(!getObj())returnfalse;132.133.functiongetp(p,d){returnp!=undefined?p:d;}134.135.functiongetObj(){136.137.vari,j,tmpObj;138.139.for(i=0,j=xmlPool.length;ij;i++)if(xmlPool[i].readyState==0||xmlPool140.141.142.143.[i].readyState==4)returnxmlPool[i];144.145.try{tmpObj=newXMLHttpRequest;}146.147.catch(e){148.149.for(i=0,j=xmlVersion.length;ij;i++){150.151.try{tmpObj=newActiveXObject(xmlVersion[i]);}catch(e2){152.153.154.155.continue;}156.157.break;158.159.}160.161.}162.163.if(!tmpObj)returnfalse;164.165.else{xmlPool[xmlPool.length]=tmpObj;returnxmlPool[xmlPool.length-1];}166.167.}168.169.function$(id){returndocument.getElementById(id);}170.171.function$N(d){varn=d*1;return(isNaN(n)?0:n);}172.173.function$VO(v){return(typeof(v)==string?(v=$(v))?v:false:v);}174.175.function$GID(){return((newDate)*1);}176.177.function$SOP(id,ct){objPool[id+]=ct;}178.179.function$LOP(id){return(objPool[id+]);}180.181.function$SRP(f,r,p){return(function(s){s=f(s);for(vari=0;ir.length;i++)182.183.184.185.s=s.replace(r[i],p[i]);return(s);});}186.187.function$GEC(cs){188.189.if(cs.toUpperCase()==UTF-8)return(encodeURIComponent);190.191.elsereturn($SRP(escape,[/\+/g],[%2B]));192.193.}194.195.function$ST(obj,text){196.197.varnn=obj.nodeName.toUpperCase();198.199.if(INPUT|TEXTAREA|OPTION.indexOf(nn)-1)obj.value=text;200.201.elsetry{obj.innerHTML=text;}catch(e){};202.203.}204.205.function$CB(cb){206.207.if(typeof(cb)==function)returncb;208.209.else{210.211.cb=$VO(cb);212.213.if(cb)return(function(obj){$ST(cb,obj.responseText);});214.215.elsereturnthis.oncomplete;}216.217.}218.219.function$GP(p,v,d,f){220.221.vari=0;222.223.while(iv.length){p[i]=v[i]?f[i]?f[i](v[i]):v[i]:d[i];i++;}224.225.while(id.length){p[i]=d[i];i++;}226.227.}228.229.functionsend(purl,pc,pcbf,pm,pa){230.231.varct,ctf=false,xmlObj=getObj(),ac=arguments.length,av=arguments;232.233.if(!xmlObj)returnfalse;234.235.varpmp=pm.toUpperCase()==POST?true:false;236.237.if(!pm||!purl)returnfalse;238.239.varev={url:purl,content:pc,method:pm};240.241.purl+=(purl.indexOf(?)-1?&:?)+timestamp=+$GID();242.243.xmlObj.open(pm,purl,pa);244.245.AJAX.onrequeststart(ev);246.247.if(pmp)xmlObj.setRequestHeader(Content-Type,application/x-);252.253.ct=setTimeout(function(){ctf=true;xmlObj.abort();},AJAX.timeout);254.255.varrc=function(){256.257.if(ctf){AJAX.ontimeout(ev);AJAX.onrequestend(ev);}258.259.elseif(xmlObj.readyState==4){260.261.ev.status=xmlObj.status;262.263.try{clearTimeout(ct);}catch(e){};264.265.try{if(xmlObj.status==200)pcbf(xmlObj);else266.267.268.269.AJAX.onexception(ev);}270.271.catch(e){AJAX.onexception(ev);}272.273.AJAX.onrequestend(ev);274.275.}276.277.}278.279.xmlObj.onreadystatechange=rc;280.281.if(pmp)xmlObj.send(pc);elsexmlObj.send();282.283.if(pa==false)rc();284.285.returntrue;286.287.}2

1 / 33
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功