php ajax mysql登录_Ajax+PHP+MySQL 登陆示例

1 <?php session_start();?>

2

3

4

5

6

login

7

8

9

10

11 functionchkForm() {12 if(m$('username').value== "") {13

14 alert('用户名不能为空.');15 m$('username').focus();16 return false;17

18 }19 if(m$('password').value== "") {20

21 alert('密码不能为空.');22 m$('password').focus();23 return false;24

25 }26 if(m$('password').value!= "" &&m$('username').value!= "") {27

28 varxmlhttp=createRequest();29 if(xmlhttp) {30 m$('loading').innerHTML= "loading...";31 varusername=m$('username').value;32 varpwd=m$('password').value;33 varcode=m$('txtCode').value;34 varurl= "dologin.php";35 xmlhttp.open("POST", url,true);36 xmlhttp.onreadystatechange=ValidateResult;37 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");38 xmlhttp.send("username=" +escape(username)+ "&password=" +escape(pwd)+ "&code=" +escape(code));39

40 }else{41 alert('xmlHttp创建失败.');42

43 }44

45 functionValidateResult() {46 if(xmlhttp.readyState== 4) {47 if(xmlhttp.status== 200) {48 if(xmlhttp.responseText!= "") {49

50 //window.alert(xmlhttp.responseText);

51 varobj=eval("(" +xmlhttp.responseText+ ")");52 if(obj.result== true) {53 alert("提示:" +obj.info);54 window.location= 'index.php';55

56 }else{57 alert("错误:" +obj.info);58

59 }60 }else{61 window.alert("从服务器获取失败");62

63 window.location.reload();64 }65 m$('loading').innerHTML= "";66 }67 }68

69 }70

71

72 }73

74 }75

76 functionm$(id) {77 returndocument.getElementById(id);78 }79

80 functionchangeCode() {81 varxmlhttp=createRequest();82 if(xmlhttp) {83 m$('loading').innerHTML= "loading...";84 vardt= newDate().getTime();85 //alert(dt);

86 varurl= "function/imagecode.php?dummay" +escape(dt);87 xmlhttp.open("GET", url,true);88 xmlhttp.onreadystatechange=ValidateResult;89 xmlhttp.send(null);90

91 }else{92 alert('xmlHttp创建失败.');93

94 }95

96 functionValidateResult() {97 if(xmlhttp.readyState== 4) {98 if(xmlhttp.status== 200) {99 vardt= newDate().getTime();100 varurl= "function/imagecode.php?dummay" +escape(dt);101 m$('imgCode').src= "function/imagecode.php?dummay" +escape(dt);102 m$('loading').innerHTML= "";103 }104 }105

106 }107 }108

109 functionshowTool() {110 $('#divToolTip').css("display","block");111 }112

113 functionhideTool() {114 $('#divToolTip').css("display","none");115 }116 window.οnlοad=initPage;117

118 functioninitPage() {119 $('#divToolTip').css("display","none");120 }121

122

123

124

125

126

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值