您的位置:首页 > 其它

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); }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: