码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-06-17 18:33:11      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:min   note   feed   天才   服务   code   返回   hicon   div   

话不多说,代码:

$(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‘=>‘验证码不正确‘));  
            }  

 

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

标签:min   note   feed   天才   服务   code   返回   hicon   div   

原文地址:http://www.cnblogs.com/lgqtecng/p/7040598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!