程序开发

关于Asp的ajax例子

时间:2013-10-25 21:20:53  作者:www.solgle.com  来源:说歌社区  查看:293  评论:0
内容摘要:R1.html

R1.html

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript" type="text/javascript" src="main.js"></script>
</head>

<body>
<form id="form1" name="form1" method="post" action="#">
<table width="525" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="204"><p align="right">****账号:</p></td>
<td width="306"><input name="StockId" type="text" id="StockId" /></td>
</tr>
<tr>
<td><p align="right">身份证号:</p></td>
<td><input name="UserIdCard" type="text" id="UserIdCard" /></td>
</tr>
<tr>
<td><p align="right">手机号码:</p></td>
<td><input name="Mobile" type="text" id="Mobile" /></td>
</tr>
<tr>
<td><p align="right">E-mail:</p></td>
<td><input name="Email" type="text" id="Email" /></td>
</tr>
<tr>
<td><p align="right">设置密码:</p></td>
<td><input name="Pwd" type="text" id="Pwd" /></td>
</tr>
<tr>
<td><p align="right">确认密码:</p></td>
<td><input name="Pwd1" type="text" id="Pwd1" /></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input name="rbutton" type="button" id="rbutton" value="注册" onclick="r('alertinfo')" />
</div></td>
</table>
</form>
<div id="alertinfo" align="center"></div>
</body>
</html>

r1.asp

<%
StockId = Request.QueryString("StockId")
UserIdCard = Request.QueryString("UserIdCard")
Mobile = Request.QueryString("Mobile")
Email = Request.QueryString("Email")
Pwd = Request.QueryString("Pwd")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.mappath("/Data/sdcms_data.mdb")
Set rs = Server.CreateObject("adodb.recordset")
sqlstr="select * from UserInfo where StockID='"&StockID&"'"
rs.Open sqlstr,conn,1,3
if rs.Eof then
status=1
errorid=0
else
if UserIdCard <> rs("UserIdCard") then
status=0
errorid=1
else
if rs("Flag") = True then
status=0
errorid=2
else
rs("Mobile").Value=Mobile
rs("Email").Value=Email
rs("Pwd").Value=Pwd
rs("Flag").Value=True
rs.Update
status=0
errorid=3
end if
end if
end if
rs.close
Set rs=Nothing
conn.close
Set conn=Nothing

With Response
.ContentType = "text/XML"
.write("<?xml version=""1.0"" encoding=""utf-8""?>")
.write("<result>")
.write("<status>"&status&"</status>")
.write("<errorid>"&errorid&"</errorid>")
.write("</result>")
End with
%>

 

main.js

// JavaScript Document
var xmlHttp;
var viewModel;//view model
var xmlDoc;//response text
var xmlImage="<img src=\"/upfile/wait_snake.gif\" alt=\"loading...\" width=\"16\" height=\"16\" />";

//Create asynchronism object
function createXMLHttpRequest() {
xmlHttp = false;
if(window.XMLHttpRequest) { //Mozilla
xmlHttp=new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {//mime
xmlHttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttp) { // can't create
window.alert("Sorry , Can't create XMLHttpRequest object.");
return false;
}
}


/*
*
* function view Page
* model:the model which will show page content
* page:will view page
* suf:the page suffix
* variable:
*/
function requestGetPage(model,page,suf,variable)
{

createXMLHttpRequest();
viewModel=model;
xmlDoc="page is requesting...";
document.getElementById(model).innerHTML=xmlImage+xmlDoc;
if(variable!="")
{
variable=variable+"&";
}
if(suf!="")
{
suf="."+suf;
}
url=page+suf+"?"+variable+"time="+new Date().getTime()+"";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange =responseGetPage;
xmlHttp.send(null);

}
function responseGetPage()
{
if (xmlHttp.readyState == 4)
{

if (xmlHttp.status == 200)
{
document.getElementById(viewModel).innerHTML=xmlHttp.responseText;
}
else
{
document.getElementById(viewModel).innerHTML="";
alert("Server is exceptional or your computer is not online!");
document.getElementById(viewModel).innerHTML="";

}
}
else if(xmlHttp.readyState!=1&&xmlHttp.readyState!=2&&xmlHttp.readyState!=3)
{
alert("Error,Please check your computer,make sure it is online");
document.getElementById(viewModel).innerHTML="Error,Please try again!";
}
}

//查询****
function searchStock(model)
{
var StockId=document.getElementById("StockId").value;
var UserIdCard=document.getElementById("UserIdCard").value;
var Pwd=document.getElementById("Pwd").value;
if(StockId=="")
{
alert("错误:\n证券帐号不能为空!");
return;
}
if(UserIdCard=="")
{
alert("错误:\n身份证号不能为空!");
return;
}
if(Pwd=="")
{
alert("错误:\n密码不能为空!");
return;
}
document.getElementById("searchbutton").disabled=true;
createXMLHttpRequest();
viewModel=model;
xmlDoc="正在查询...";
document.getElementById(viewModel).innerHTML=xmlImage+xmlDoc;
createXMLHttpRequest();
var variable="StockId="+StockId+"&UserIdCard="+UserIdCard+"&Pwd="+Pwd;
url="checkinfo.asp?"+variable+"&time="+new Date().getTime()+"";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange =responseSearch;
xmlHttp.send(null);
}

function responseSearch()
{
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var responsexml = xmlHttp.responseXML;
var status = responsexml.getElementsByTagName("status")[0].firstChild.nodeValue;
var errorid=responsexml.getElementsByTagName("errorid")[0].firstChild.nodeValue;
if(status==1) {
location.replace("searchstock.asp");
}
else{

if(errorid==1)
{
alert("证券帐号不存在!");
}
if(errorid==2)
{
alert("身份证号码错误!");
}
if(errorid==3)
{
alert("密码错误!");
}
if(errorid==4)
{
alert("账户未注册,请先注册!");
}
document.getElementById(viewModel).innerHTML="";
document.getElementById("searchbutton").disabled=false;
}
}
else
{
document.getElementById(viewModel).innerHTML="";
alert("服务器异常或网络中断,请稍后再试");
document.getElementById("searchbutton").disabled=false;
}
}
}
//注册
function r(model)
{
var StockId=document.getElementById("StockId").value;
var UserIdCard=document.getElementById("UserIdCard").value;
var Mobile=document.getElementById("Mobile").value;
var Email=document.getElementById("Email").value;
var Pwd=document.getElementById("Pwd").value;
var Pwd1=document.getElementById("Pwd1").value;
if(StockId=="")
{
alert("错误:\n ****账号不能为空!");
return;
}
if(UserIdCard=="")
{
alert("错误:\n 身份证号不能为空!");
return;
}
if(Mobile=="")
{
alert("错误:\n 手机号码不能为空!");
return;
}
if(Email=="")
{
alert("错误:\n EMAIL不能为空!");
return;
}
if(Pwd=="")
{
alert("错误:\n 密码不能为空!");
return;
}
if(Pwd1=="")
{
alert("错误:\n 请确认密码!");
return;
}
if(Pwd!=Pwd1)
{
alert("错误:\n 密码必须相同!");
return;
}
document.getElementById("rbutton").disabled=true;
createXMLHttpRequest();
viewModel=model;
xmlDoc="正在注册...";
document.getElementById(viewModel).innerHTML=xmlImage+xmlDoc;
createXMLHttpRequest();
var variable="StockId="+StockId+"&UserIdCard="+UserIdCard+"&Mobile="+Mobile+"&Email="+Email+"&Pwd="+Pwd;
url="r1.asp?"+variable+"&time="+new Date().getTime()+"";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange =responser;
xmlHttp.send(null);
}

function responser()
{
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var responsexml = xmlHttp.responseXML;
var status = responsexml.getElementsByTagName("status")[0].firstChild.nodeValue;
var errorid = responsexml.getElementsByTagName("errorid")[0].firstChild.nodeValue;
if(status==1) {
alert("该账号未在公司登记");
location.replace("index.htm");
}
else {
if(errorid==1) {
alert("身份证号错误!");
}
if(errorid==2) {
alert("账号已经注册!");
}
if(errorid==3) {
alert("注册成功!");
location.replace("index.htm");
}
document.getElementById(viewModel).innerHTML="";
document.getElementById("rbutton").disabled=false;
}
}
else
{
document.getElementById(viewModel).innerHTML="";
alert("服务器异常或网络中断,请稍后再试");
document.getElementById("rbutton").disabled=false;
}
}
}


标签:关于Asp的ajax例子 

solgle.com 版权所有,欢迎分享!!!

相关文章
    相关评论
       Copyright © 2013-2020 solgle.com,All rights reserved.[solgle.com] 公安机关备案号:51010802000219
    Email:solgle@solgle.com; weixin:cd1008610000 ICP:蜀ICP备14011070号-1