thinkphp3.2.3验证码错误

浏览:1130 发布日期:2017/07/03 分类:求助交流

//ajax校验验证码
function checkCode(){
$code = I('post.code'); //获得用户输入的验证码
$vry = new \Think\Verify();
if($vry -> check($code)){
echo json_encode(array('status'=>1));
}else{
echo json_encode(array('status'=>2));
}
//$this -> display();
}
}




login.html
<script type="text/javascript">
var code_flag = false; //验证码是否通过验证
function check_code(){
//获得输入的验证码
var code = $('#captcha').val();
if(code.length==4){
//触发ajax
$.ajax({
url:"{:U('checkCode')}",
data:{'code':code},
dataType:'json',
type:'post',
success:function(msg){
if(msg.status==1){
$('#code_check_result').html('<span style="color:green">验证码正确</span>');
code_flag = true;
return ;
}else{
$('#code_check_result').html('<span style="color:red">验证码错误</span>');
code_flag = false;
return ;
}
}
});
}
}


</script>
最佳答案
评论( 相关
后面还有条评论,点击查看>>