asp+ajax序列号发放程序(三)

下面是获取序列号的程序gsn.asp

<!-- #include file = "gl/conn.inc" -->    

<%    

if Session("GetSN") <> "" then   

response.write "EORROR"   

else   

Ip_address=Request.ServerVariables ("HTTP_X_FORWARDED_FOR")   

     If Ip_address=""      Then   

           Ip_address= Request.ServerVariables ("REMOTE_ADDR")   

     end if  

sql="select top 1 * from sn_list where sta=0"   

set rs=conn.execute(sql)   

if   rs.eof   then      

     response.write "EMPTY"      

else   

response.write rs("sn")   

squ="Update sn_list SET sta = '-1',out_time=now(),ip='" & Ip_address & "'Where (((id)=" & rs("id")& "))"   

Session("GetSN") = 1      

conn.execute(squ)   

end if   

end if   

conn.Close   

Set conn = Nothing   

%>

asp+ajax序列号发放程序(二)

下面是主页index.htm和检查验证码输入的程序yz.asp





测试系统






"请输入该验证码"

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Response.ContentType="text/xml"
If IsEmpty(Session("GetCode")) or Session("GetCode") <> Request.querystring("Code") Then
response.write("")
Else
  Session("GetCode") = Empty    ' 清空Session
response.write("")
End If
%>   

asp+ajax序列号发放程序(一)

刚接触asp和ajax,自己做了一个简单的序列号发放程序,功能很简单,在网页上输入正确的验证码后立即返回一个序列号,可限定间隔时间,需要用到access数据库。

下面是核心的ajax.js文件

function ShowMsg(id,msg,color){
document.getElementById(id).innerHTML =msg;
document.all.msg.style.color=color;
}
function checkfm(fm){
if(form.code.value.length < 4){
ShowMsg("msg", "请输入验证码!",'red');
form.code.focus();
return false;
}
return true;
}
function getXmlHttp(){
var http_request = false;
if (window.XMLHttpRequest){
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType){
http_request.overrideMimeType('text/xml');
}
}else if (window.ActiveXObject){
try{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e)
{}
}
}
if (!http_request){
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return http_request;
}
function onStateChange()
{
if(ajaxObj.readyState == 4 ){
if(ajaxObj.status == 200) {
//alert(ajaxObj.responseText );
//var json = eval('(' + ajaxObj.responseText + ')');
var xmlDoc=ajaxObj.responseXML.documentElement;
if(xmlDoc.tagName=="EORROR"){
ShowMsg("msg","验证码输入错误",'red');
}else{
ShowMsg("msg","正在获取序列号……",'green');
get_sn();
}
//验证完成
} else { //页面不正常
//document.getElementById("msg").innerHTML ="您所请求的页面有异常。";
ShowMsg("msg","您所请求的页面有异常。",'red');
}
}else{
//ShowMsg("msg","连接错误!",'red'); //返回为空时提示!
}

}
function yz(){
//document.getElementById("msg").innerHTML = "正在连接……";
ShowMsg("msg", "正在连接……","green");
var url="./yz.asp?code="+form.code.value;
ajaxObj = getXmlHttp();
ajaxObj.onreadystatechange = onStateChange;
ajaxObj.open("GET", url, true);
ajaxObj.setRequestHeader('If-Modified-Since', '0');
ajaxObj.send(null);
}
function onGetSN(){
if(as.readyState == 4 ){
if(as.status == 200) {
if (as.responseText.toString()=="EORROR"){
ShowMsg("msg","你已经领过了,请稍后再来!",'red');
form.rush.disabled=true;
}else if (as.responseText.toString()=="EMPTY"){
ShowMsg("msg","暂时已经领完,请稍后再来!",'blue');
form.rush.disabled=true;
}else{
var str= as.responseText.toString() + "
" + "序列号已领取,请妥善保管。";
ShowMsg("msg",str,'green');
form.rush.disabled=true;
}
}
}
}
function get_sn(){
var ul="./gsn.asp";
as = getXmlHttp();
as.onreadystatechange = onGetSN;
as.open("GET",ul,true);
as.setRequestHeader('If-Modified-Since', '0');
as.send(null);
}