<?php session_start();?>
<!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>login</title>
<link rel=
"stylesheet"
type=
"text/css"
href=
"CSS/login.css"
/>
<script src=
"JS/ajaxhelper.js"
type=
"text/javascript"
></script>
<script src=
"JS/jquery-1.3.2.min.js"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
function
chkForm() {
if
(m$(
'username'
).value ==
""
) {
alert(
'用户名不能为空.'
);
m$(
'username'
).focus();
return
false;
}
if
(m$(
'password'
).value ==
""
) {
alert(
'密码不能为空.'
);
m$(
'password'
).focus();
return
false;
}
if
(m$(
'password'
).value !=
""
&& m$(
'username'
).value !=
""
) {
var
xmlhttp = createRequest();
if
(xmlhttp) {
m$(
'loading'
).innerHTML =
"<font color='red'>loading...</font>"
;
var
username = m$(
'username'
).value;
var
pwd = m$(
'password'
).value;
var
code = m$(
'txtCode'
).value;
var
url =
"dologin.php"
;
xmlhttp.open(
"POST"
, url, true);
xmlhttp.onreadystatechange = ValidateResult;
xmlhttp.setRequestHeader(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
xmlhttp.send(
"username="
+ escape(username) +
"&password="
+ escape(pwd) +
"&code="
+ escape(code));
}
else
{
alert(
'xmlHttp创建失败.'
);
}
function
ValidateResult() {
if
(xmlhttp.readyState == 4) {
if
(xmlhttp.status == 200) {
if
(xmlhttp.responseText !=
""
) {
var
obj =
eval
(
"("
+ xmlhttp.responseText +
")"
);
if
(obj.result == true) {
alert(
"提示:"
+ obj.info);
window.location =
'index.php'
;
}
else
{
alert(
"错误:"
+ obj.info);
}
}
else
{
window.alert(
"从服务器获取失败"
);
window.location.reload();
}
m$(
'loading'
).innerHTML =
""
;
}
}
}
}
}
function
m$(id) {
return
document.getElementById(id);
}
function
changeCode() {
var
xmlhttp = createRequest();
if
(xmlhttp) {
m$(
'loading'
).innerHTML =
"<font color='red'>loading...</font>"
;
var
dt =
new
Date
().getTime();
var
url =
"function/imagecode.php?dummay"
+ escape(dt);
xmlhttp.open(
"GET"
, url, true);
xmlhttp.onreadystatechange = ValidateResult;
xmlhttp.send(null);
}
else
{
alert(
'xmlHttp创建失败.'
);
}
function
ValidateResult() {
if
(xmlhttp.readyState == 4) {
if
(xmlhttp.status == 200) {
var
dt =
new
Date
().getTime();
var
url =
"function/imagecode.php?dummay"
+ escape(dt);
m$(
'imgCode'
).src =
"function/imagecode.php?dummay"
+ escape(dt);
m$(
'loading'
).innerHTML =
""
;
}
}
}
}
function
showTool() {
$(
'#divToolTip'
).css(
"display"
,
"block"
);
}
function
hideTool() {
$(
'#divToolTip'
).css(
"display"
,
"none"
);
}
window.onload = initPage;
function
initPage() {
$(
'#divToolTip'
).css(
"display"
,
"none"
);
}
</script>
</head>
<body>
<div style=
"background-color:#2A3F55; height:80px;"
>
</div>
<div style=
"min-height:500px;"
>
<div
class
=
"left"
>
<div style=
"margin:120px auto auto auto; height:300px; text-align:left"
>
<div style=
"font-size:26px;color:#2A3F55; text-align:center;"
>Ajax PHP Demo System
<img src=
"/static/imghw/default1.png"
data-src=
"Images/appstorm-icon.png"
class
=
"lazy"
alt=
"appcation storm image"
style=
"max-width:90%"
/>
</div>
<br/>
<hr style=
"border:dashed thin #2A3F55;width:70%; text-align:center;"
/>
<div style=
"font-size:13px;color:#999999; margin:20px auto 0 auto; padding-left:200px;"
>
Author:<a href=
"#"
onmousemove=
"showTool();"
onmouseout=
"hideTool();"
>wangming</a>
</div>
<div style=
"font-size:13px;color:#999999;margin:20px auto auto auto; padding-left:200px;"
>DateTime:2009-9-1</div>
<div style=
"font-size:13px;color:#999999;margin:20px auto auto auto; padding-left:200px;"
>Version:1.0.0</div>
<div style=
"font-size:13px;color:#999999;margin:20px auto auto auto; padding-left:200px;"
>Email:wangmingemail@163.com </div>
<div id=
"divToolTip"
>
<img src=
"/static/imghw/default1.png"
data-src=
"Images/ming.jpg"
class
=
"lazy"
height=
"86px;"
/ alt=
"PHP如何通过AJAX方式实现登录功能_PHP"
>
<span
class
=
"authordes"
>
<br/>
姓名:wangming<br/>
电商06-2<br/>
</span>
</div>
</div>
</div>
<div
class
=
"right"
>
<form>
<br/>
<table
class
=
"flogin"
>
<tr>
<td>用户名:</td>
<td><input type=
"text"
name=
"username"
id=
"username"
/></td>
<td></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type=
"password"
name=
"password"
id=
"password"
/></td>
<td></td>
</tr>
<tr>
<td>验证码:</td>
<td>
<input type=
"text"
name=
"txtCode"
id=
"txtCode"
size=
"12"
/>
<img src=
"/static/imghw/default1.png"
data-src=
"function/imagecode.php"
class
=
"lazy"
id=
"imgCode"
alt=
"image code"
height=
"22px;"
style=
"max-width:90%"
/>
</td>
<td><input type=
"button"
class
=
"btnrefresh"
onclick=
"changeCode();"
/></td>
</tr>
<tr>
<td></td>
<td><input type=
"button"
class
=
"btnlogin"
onclick=
"chkForm();"
/></td>
<td></td>
</tr>
<tr>
<td></td>
<td><span id=
"loading"
></span></td>
<td><span id=
"code"
></span></td>
</tr>
</table>
</form>
</div>
</div>
<div style=
"background-color:#2A3F55; height:60px; margin:auto 0 0 0; clear:both; text-align:center; line-height:60px; color:#FFFFFF;font-size:12px;"
>
&
copy
;Copyright 2015.
</div>
</body>
</html>