<!--注冊模塊-->default.ASP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xHtml1-transitional.dtd">
<html XMLns="http://www.w3.org/1999/xHtml">
<head>
<title>AJax - Sample1</title>
<meta http-equiv="Content-Type" content="text/Html; charset=utf-8" /> //請一定要將此頁的編碼設為UTF-8,否則將出現亂碼
<meta name="author" content="tonyhl[at]126.com" />
<meta http-equiv="pragma" content="no-cache"/>
<script language="Javascript" type="text/Javascript" src="reg.JS"></script>
<link rel="stylesheet" href="css.css" type="text/CSS" media="all"/>
<style type="text/CSS">
<!--
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 409px;
top: 88px;
}
-->
</style>
</head>
<body>
<h2>AJax應用實例: 注冊模塊</h2>
<div id="Layer1">
<div id="msg"></div>
</div>
ID: <input type="text" id="regid" />
Password: <input type="password" id="regpassWord" />
<input name="f" type="file" />
<input type="submit" id="regsubmit" value="注冊" />
<h2>當注冊ID為 tony的用戶時,後台驗證該ID已存在,返回提示信息<br />
為突出顯示無刷新效果,服務器端程序將自動進行百萬加法運算
</h2>
</body>
</Html>
<!----表單數據提交腳本--->REG.JS
function GE(a){return document.getElementById(a);}
function Check(){
if(GE('regid').value==''){GE('msg').innerHtml='ID不能為空';return false}
if(GE('regpassWord').value==''){GE('msg').innerHtml='passWord 不能為空';return false}
var X=new ActiveXObject("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');
var SendData = '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編碼,否則將出現亂碼.
<%
Dim regid, regpassWord, str
regid=Request.Form("regid")
regpassword=Request.Form("regpassWord")
f=Request.Form("file")
Dim i, ii
ii = 0
For i = 0 To 1000000
ii = ii + i
Next
If regid="" or regpassWord="" then
str = "ID和PASSWord必須填寫"
Else
If regid <> "tony" Then
str = "注冊成功,ID為" & regid & " , 密碼為" & regpassWord&f
Else
str = "注冊失敗,ID已經存在"
End If
End if
Response.Write "GE('msg').innerHtml='" & str & "';GE('regsubmit').disabled=false"
Response.End
%>