这套源码能实现AJAX的功能,可是要比AJAX简单多了,只需要两个文件就可以实现
大家有什么意见或建议,或对代码有疑问请提出,
default.asp
<html>
<head>
<meta http-equiv="Content-Type" c />
<link rel="STYLESHEET" type="text/css" href="inc/Style.css">
<script language="JavaScript" type="text/javascript">
function logins(n){
document.scripts[1].src = "login.asp?fun=" + n;
}
function chkGN()
{
document.scripts[1].src = "login.asp?fun=2&names=" + myform.names.value + "&pass=" +myform.pass.value + "&autoload=" +myform.autoload.checked
;
}
</script>
<script language="JavaScript" type="text/javascript" src=""></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">logins(1);</script>
<TABLE border=bordercolor=#000000 align=left bgColor=#ffffff>
<TBODY>
<TR>
<TD width="100" height="18">fghfgjfj</TD>
<TD width="136"> </TD>
<TR>
<TD></TD>
<TD height="62" ID="login"> </TD>
</TR></TBODY></TABLE></P>
</body>
</html>
login.asp
<!--#include file="../inc/conn.asp" -->
<%
select case request("fun")
case 1:show
case 2:loginin
case 3:loginout
case 4:loginout
end select
function show()
if session("UserName")="" then session("UserName") = Request.Cookies("login")("UserName")
str="document.getElementById('login').innerHTML = """
str = str & "<table align=center border=0 cellspacing=0 cellpadding=0 width=136 height=62>"
if session("UserName")<>"" then
str="document.getElementById('login').innerHTML = """
str = str & "<tr><td align=center>当前用户:" & session("UserName") & "<br><input type=button value=退出登录 onclick=logins(3)></td></tr>"
else
str = str & "<form name='myform'>"
str = str & "<tr><td nowrap>帐号:</td><td><input type=text name=names size=15></td></tr>"
str = str & "<tr><td nowrap>密码:</td><td><input type=password name=pass size=15></td></tr>"
str = str & "<tr><td colspan=2 align=center><a href='javascript:chkGN();'>注册</a> <a href='javascript:chkGN();'>进入</a>自动登录<input name='autoload' type='checkbox' value='1'></td></tr>"
str = str & "</form>"
end if
str = str & "</table>"";"
response.write str
end function
function loginin()
str="document.getElementById('login').innerHTML = """
str = str & "<table align=center border=0 cellspacing=0 cellpadding=0 width=136 height=62>"
if not (request("names")="" or request("pass")="") then
set rs=conn.execute("select UserName,PassWord from Personnel where UserName='"&request("names")&"'")
if not rs.eof then
if request("pass")=rs("PassWord") then
session("UserName")=rs("UserName")
if request("autoload")="true" then
Response.Cookies("login")("UserName") = rs("UserName")
Response.Cookies("login").Expires = "2038-1-1"
end if
show()
response.end
Else
str = str & "<tr><td align=center>密码输入错误,请重新输入正确的密码 <input type=button value=返 回 onclick=logins(1)></td></tr>"
end if
Else
str = str & "<tr><td align=center>没有此用户存在,请输入正确的用户名。 <input type=button value=返 回 onclick=logins(1)></td></tr>"
end if
rs.close
set rs=nothing
else
str = str & "<tr><td align=center>错误!用户名和密码都必须填写 <input type=button value=返 回 onclick=logins(1)></td></tr>"
end if
str = str & "</table>"";"
response.write str
end function
function loginout()
session("UserName")=""
Session.abandon
Response.Cookies("login")("UserName") = ""
show()
end function
%>
数据库结构:
UserName 用户名
PassWord 密码