Example ajax registered user and form submission effect code<!--Registration module-->default.asp
Copy the code code as follows:
<!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 /> //Please be sure to set the encoding of this page to UTF-8, otherwise garbled characters will appear.
<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 application example: registration module</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=Register onclick=Check() />
<h2>When registering a user with ID tony, the background verifies that the ID already exists and returns a prompt message<br />
To highlight the no-refresh effect, the server-side program will automatically perform a million addition operations
</h2>
</body>
</html>
Copy the code code as follows:
<!----Form data submission script--->REG.JS
function GE(a){return document.getElementById(a);}
function Check(){
if(GE('regid').value==''){GE('msg').innerHTML='ID cannot be empty'; return false}
if(GE('regpassword').value==''){GE('msg').innerHTML='password cannot be empty';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=Submitting data...}
};
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='Your browser does not support XMLHttpRequest'
}
}
<!---Program processing--->reg.asp
Copy the code code as follows:
<%@ LANGUAGE=VBSCRIPT CODEPAGE=65001%>//CODEPAGE must be 650001, otherwise garbled characters will appear. If there is HTML text, it must be set to UTF-8 encoding, otherwise garbled characters will appear.
<%
Dim regid, regpassword, str
regid=Request.Form(regid)
regpassword=Request.Form(regpassword)
f=Request.Form(file)
Dim i, ii
i = 0
For i = 0 To 1000000
ii = ii + i
Next
If regid= or regpassword= then
str = ID and PASSWORD must be filled in
Else
If regid <> tony Then
str = Registration successful, ID is & regid &, password is & regpassword&f
Else
str = Registration failed, ID already exists
End If
End if
Response.Write GE('msg').innerHTML=' & str & ';GE('regsubmit').disabled=false
Response.End
%>