AJAX实例
2015-09-14 17:00
260 查看
jquery代码
$("#bat").click(function(){
var aa=$("#name").val();//姓名
var bb=$("#pwd").val();//密码
var cc=$("#code").val();//验证码
$.ajax({
data:{code:cc,name:aa,pwd:bb},
datatype:"POST",
url:"__APP__/zhaopin/index/dengluh",
success:function(data){
if (!data.result){//返回登陆结果失败,弹出提示
ds.dialog.tips(data.msg,1,true,false);//这里用了dialog提示插件,可以自己改为alert,或其他的
// $("#yzm").click();
}else{//返回登陆结果成功,弹出提示,
ds.dialog.tips("登陆成功",1,true,false);
setTimeout("location.href='__APP__/zhaopin/index/jianlilb';", 1000); //延时1000ms后转入系统界面
}
}
})
}
})html代码
<form method="post" id="form1" action="{:U('zhaopin/index/dengluh')}">
<div class="row">
<div id="msg" style="color:red"></div>
<div class=" form-group col-md-12" >
<label>帐号</label>
<label id="namemsg" style="color:red"></label>
<input type="text" id="name" name="name" maxlength="18" class="form-control" placeholder="请输入帐号">
</div>
<div class=" form-group col-md-12" >
<label>密码</label>
<label id="pwdmsg" style="color:red"></label>
<input type="password" id="pwd" name="pwd"maxlength="11" class="form-control" placeholder="请输入密码">
</div>
<div class=" form-group col-md-12" >
<label>验证码</label>
<label id="yzmmsg" style="color:red"></label>
<div class="row">
<div class="col-md-5" >
<img src="{:U('zhaopin/index/verify','','')}" id="yzm" onclick="this.src='__APP__/zhaopin/index/verify/id/'+Math.random()"/>
</div>
<div class="col-md-offset-1 col-md-6">
<input type="text" id="code" name="code"maxlength="4" class="form-control" placeholder="请输入验证码">
</div>
</div>
</div>
</div>
<div class="row">
<div class=" form-group col-md-6 col-md-offset-3" >
<button type="button" id="bat" class="btn btn-primary ">登 陆</button>
</div>
</div>
</form>后台代码
public function dengluh(){
$name=I('name');
$pwd=md5(I('pwd'));
$code=I('code');
if(check_code($code)==false){
$da=array(
'msg'=>"验证码错误!",
'result'=>0,
);
}else{
$d=M('manage')->where(array('name'=>$name))->find();
if(!$d['id']){
$da=array(
'msg'=>"用户名不存在!",
'result'=>0,
);
}else if($d['pwd']!==$pwd){
$da=array(
'msg'=>"密码错误!",
'result'=>0,
);
}else{
$da=array(
'msg'=>"登陆成功1",
'result'=>1,
);
}
}
SESSION('username',$d['name']);
$this->ajaxreturn($da); }
$("#bat").click(function(){
var aa=$("#name").val();//姓名
var bb=$("#pwd").val();//密码
var cc=$("#code").val();//验证码
$.ajax({
data:{code:cc,name:aa,pwd:bb},
datatype:"POST",
url:"__APP__/zhaopin/index/dengluh",
success:function(data){
if (!data.result){//返回登陆结果失败,弹出提示
ds.dialog.tips(data.msg,1,true,false);//这里用了dialog提示插件,可以自己改为alert,或其他的
// $("#yzm").click();
}else{//返回登陆结果成功,弹出提示,
ds.dialog.tips("登陆成功",1,true,false);
setTimeout("location.href='__APP__/zhaopin/index/jianlilb';", 1000); //延时1000ms后转入系统界面
}
}
})
}
})html代码
<form method="post" id="form1" action="{:U('zhaopin/index/dengluh')}">
<div class="row">
<div id="msg" style="color:red"></div>
<div class=" form-group col-md-12" >
<label>帐号</label>
<label id="namemsg" style="color:red"></label>
<input type="text" id="name" name="name" maxlength="18" class="form-control" placeholder="请输入帐号">
</div>
<div class=" form-group col-md-12" >
<label>密码</label>
<label id="pwdmsg" style="color:red"></label>
<input type="password" id="pwd" name="pwd"maxlength="11" class="form-control" placeholder="请输入密码">
</div>
<div class=" form-group col-md-12" >
<label>验证码</label>
<label id="yzmmsg" style="color:red"></label>
<div class="row">
<div class="col-md-5" >
<img src="{:U('zhaopin/index/verify','','')}" id="yzm" onclick="this.src='__APP__/zhaopin/index/verify/id/'+Math.random()"/>
</div>
<div class="col-md-offset-1 col-md-6">
<input type="text" id="code" name="code"maxlength="4" class="form-control" placeholder="请输入验证码">
</div>
</div>
</div>
</div>
<div class="row">
<div class=" form-group col-md-6 col-md-offset-3" >
<button type="button" id="bat" class="btn btn-primary ">登 陆</button>
</div>
</div>
</form>后台代码
public function dengluh(){
$name=I('name');
$pwd=md5(I('pwd'));
$code=I('code');
if(check_code($code)==false){
$da=array(
'msg'=>"验证码错误!",
'result'=>0,
);
}else{
$d=M('manage')->where(array('name'=>$name))->find();
if(!$d['id']){
$da=array(
'msg'=>"用户名不存在!",
'result'=>0,
);
}else if($d['pwd']!==$pwd){
$da=array(
'msg'=>"密码错误!",
'result'=>0,
);
}else{
$da=array(
'msg'=>"登陆成功1",
'result'=>1,
);
}
}
SESSION('username',$d['name']);
$this->ajaxreturn($da); }
相关文章推荐
- 单例-dispatch_once和@synchronized
- Json
- Weblogic启动不输用户名密码
- 第3周实践项目--顺序表的基本运算(1)
- 全面了解 iOS 静态库开发
- NSString 字符串替换
- 午后时光
- Android系统版本与API Level对照表
- 如何判断整数x的二进制中含有多少个1
- mysql中" ' "和 " ` "的区别
- 正则表达式详解
- 数据类型(Data Type)
- 实现分页功能 web
- NSString 字符串替换
- 前App Store高管揭秘:关于“苹果推荐”的七大真相
- List
- Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对
- 第二周 项目1 函数参数传递的三种方式
- ffmpeg 读取MPEG-TS流,切割TS流支持【HLS协议】
- Java连接六类数据库技巧全攻略