<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&dt=1225678105875&lmt=1219829521&prev_slotnames=1891601125&output=html&slotname=3685991503&correlator=1225678105234&url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F08%2F1435.html&ea=0&ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__71.html&frm=0&ga_vid=794657364.1225360561&ga_sid=1225676616&ga_hid=2054030497&ga_fc=true&flash=9.0.124.0&u_h=768&u_w=1024&u_ah=715&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency></iframe>
<!--注册模块-->default.asp
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ajax-Sample1</title>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>//请一定要将此页的编码设为UTF-8,否则将出现乱码
<metaname="author"content="tonyhl[at]126.com"/>
<metahttp-equiv="pragma"content="no-cache"/>
<scriptlanguage="javascript"type="text/javascript"src="reg.js"></script>
<linkrel="stylesheet"href="css.css"type="text/css"media="all"/>
<styletype="text/css">
<!--
#Layer1{
position:absolute;
width:200px;
height:115px;
z-index:1;
left:409px;
top:88px;
}
-->
</style>
</head>
<body>
<h2>Ajax应用实例:注册模块</h2>
<divid="Layer1">
<divid="msg"></div>
</div>
ID:<inputtype="text"id="regid"/>
Password:<inputtype="password"id="regpassword"/>
<inputname="f"type="file"/>
<inputtype="submit"id="regsubmit"value="注册"οnclick="Check()"/>
<h2>当注册ID为tony的用户时,后台验证该ID已存在,返回提示信息<br/>
为突出显示无刷新效果,服务器端程序将自动进行百万加法运算
</h2>
</body>
</html>
<!----表单数据提交脚本--->REG.JS
functionGE(a){returndocument.getElementById(a);}
functionCheck(){
if(GE('regid').value==''){GE('msg').innerHTML='ID不能为空';returnfalse}
if(GE('regpassword').value==''){GE('msg').innerHTML='password不能为空';returnfalse}
varX=newActiveXObject("Msxml2.XMLHTTP");
if(X){
GE('regsubmit').disabled=true;
X.onreadystatechange=function(){
if(X.readyState==4){
if(X.status==200){
eval(X.responseText)
}
else{GE('msg').innerHTML=X.statusText}
}
else{GE('msg').innerHTML="正在提交数据..."}
};
X.open('POST','reg.asp',true);
X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
varSendData='regid='+GE('regid').value+'®password='+GE('regpassword').value+'&file='+GE('f').value
X.send(SendData)
}
else{
GE('msg').innerHTML='你的浏览器不支持XMLHttpRequest'
}
}
<!---程序处理--->reg.asp
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>//CODEPAGE必须为650001,否则也出现乱码,如果有HTML文字,一定设为UTF-8编码,否则将出现乱码.
<%
Dimregid,regpassword,str
regid=Request.Form("regid")
regpassword=Request.Form("regpassword")
f=Request.Form("file")
Dimi,ii
ii=0
Fori=0To1000000
ii=ii+i
Next
Ifregid=""orregpassword=""then
str="ID和PASSWORD必须填写"
Else
Ifregid<>"tony"Then
str="注册成功,ID为"®id&",密码为"®password&f
Else
str="注册失败,ID已经存在"
EndIf
Endif
Response.Write"GE('msg').innerHTML='"&str&"';GE('regsubmit').disabled=false"
Response.End
%>