thinkphp 3.2.3 验证码Ajax验证 遇到异步验证了,求解答

浏览:1186 发布日期: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/Index/check_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部分

common目录下建立一个function

function check_verify($code, $id = 1,$reset = true){
    $Verify = new \Think\Verify();
    $Verify->reset=false;
    return $Verify->check($code, $id);
}

引用了Controller下

public function  check_code(){
if (IS_AJAX) {
if (check_verify(I('code'))) {
        $arr['success'] = 1;
        $array=json_encode($arr);
        print_r($array);
}else {
        $arr['success'] = 0;
        $array=json_encode($arr);
        print_r($array);
}
}
}

​<input type="text" placeholder="验证码" name="code" class="code" id="code">

<img width="75" height="25" onclick="this.src=this.src+"?"+Math.random();" alt="点击刷新" src="/anka/index.php/Admin/Index/check_code">

图片 src 如何应用function里面的验证码函数啊
最佳答案
评论( 相关
后面还有条评论,点击查看>>