ajax来判断验证码是否输入正确

浏览:2354 发布日期:2016/03/11 分类:求助交流
html  部分
<input type="text" id="code" class="code" name="code" placeholder="验证码">
<img src="__CONTROLLER__eck_code" alt="点击刷新" onclick='this.src=this.src+"?"+Math.random();' width="75" height="25"/>


jquery ajax 部分
<script type="text/javascript">
$(function(){
    var path=window.location.hostname;
    $("#code").blur(function(){
        var code=$('#code').val();
        jQuery.ajax({
            type : 'POST',
            contentType : "application/x-www-form-urlencoded",
            url :'http://'+path+ '/anka/index.php/Admin/Indexeck_code',
            data : {'code' : code},
            dataType : 'json',
              success: function(data,response){
                var resualt=data.success;
                if(code==1){
                    $('<div id="repson" />').html("<font color=red>验证码不正确</font>").appendTo('#responseMsg').fadeOut(2000);
                    $("#code").select();
                     return false;
                    }
                    else if(resualt==0){
                    return true;
                    }

            }
        });

    });
});

</script>

PHP部分
public function  check_code(){
$Verify = new \Think\Verify();
$Verify->fontSize = 30;
$Verify->length   = 4;
$Verify->useNoise = false;
$Verify->entry();
if($Verify->check(I('code'))){
    $arr['success'] = 1;
    $array=json_encode($arr);
    print_r($array);
}else{
    $arr['success'] = 0;
    $array=json_encode($arr);
    print_r($array);
}
}
问题讨论
最佳答案
评论( 相关
后面还有条评论,点击查看>>