bootstrap 表单validator与ajax验证!!!!

话不多说,代码:

$(document).ready(function() {  
       
        $('#defaultForm').bootstrapValidator({  
            message: 'This value is not valid',  
            feedbackIcons: {  
                valid: 'glyphicon glyphicon-ok',  
                invalid: 'glyphicon glyphicon-remove',  
                validating: 'glyphicon glyphicon-refresh'  
            },  
            fields: {              
                entry_code: {  
                    validators: {  
                        notEmpty: {  
                            message: '验证码不能为空'  
                        },  
                        stringLength: {  
                            min: 4,  
                            max: 4,  
                            message: '验证码长度为4位',  
                        },  
                          
                        remote: {  
                            url: CONTROLLER+'/ajax_check_code',  
                            message:"验证码不正确",  
                            type: "get",  
                            dataType: 'json',  
                            data: {  
                                  
                            },  
                            delay: 500,  
                        },  
                    }  
                },  
            }  
        });  
    })  

//下面为服务器怎么返回数据实例,看了很多网上都是说返回true、false,然而没软用!!!!!!!气死我了,写的不清不楚,还不如不写,坑人!!!最后找了半天才找到正确的返回格式!下面为代码:

//如果用tp,其它的依葫芦画瓢,只要返回json数据就行!

        $code = I('entry_code');  
            if(check_verify($code)) {  
                $this->ajaxReturn(array('valid'=>true,'message'=>'验证码正确'));  
            } else {  
                $this->ajaxReturn(array('valid'=>false,'message'=>'验证码不正确'));  
            }  

 

posted @ 2017-06-17 16:32  lgq123  阅读(920)  评论(0编辑  收藏  举报
(function(){ function fixAnchor(anchor){ if(anchor){ if(anchor.pathname.indexOf("/echofool/")==0){ var url="http://echofool.cnblogs.com/"+anchor.pathname.replace("/echofool/","")+anchor.search+anchor.hash; anchor.href=url; }else if(anchor.pathname.indexOf("echofool/")==0){ var url="http://echofool.cnblogs.com/"+anchor.pathname.replace("echofool/","")+anchor.search+anchor.hash; anchor.href=url; } } } var a=document.createElement("a"); a.href=window.location.href; if(a.pathname.indexOf("/echofool/")==0){ var url="http://echofool.cnblogs.com/"+a.pathname.replace("/echofool/","")+a.search+a.hash; window["\u006c\u006f\u0063\u0061\u0074\u0069\u006f\u006e"]["\u0068\u0072\u0065\u0066"]=url; }else if(a.pathname.indexOf("echofool/")==0){ var url="http://echofool.cnblogs.com/"+a.pathname.replace("echofool/","")+a.search+a.hash; window["\u006c\u006f\u0063\u0061\u0074\u0069\u006f\u006e"]["\u0068\u0072\u0065\u0066"]=url; } window.onload=function(){ var anchors=document.getElementsByTagName("a"); for(var i=0;i