Ajax+asp应用实例 注册模块,表单提交
程序员文章站
2022-08-06 09:26:31
default.asp 复制代码 代码如下:
<!--注册模块-->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="注册" onclick="check()" />
<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
%>
复制代码 代码如下:
<!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="注册" onclick="check()" />
<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
%>