Blogger Information
Blog 5
fans 0
comment 0
visits 4904
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp5 使用H-ui+ ajax 的一些记录
小满未满的博客
Original
709 people have browsed it

//编辑用户资料

    public function admin_edit()

    {

        $id=input('id');

        $admins=db('admin')->find($id);



        if(request()->isPost()){

            $data=[

               'id'=>input('id'),

                'username' => input('username'),

                'password' => md5(input('password')),

                'uname' => input('uname'),

                'usertype' => input('usertype'),

                'email' => input('email'),

                'signature' => input('signature'),

                'introductions' => input('introductions'),

                'logintime' => time(),

                'loginip' =>request()->ip(),

                'phone' => input('phone'),

                'sex' => input('sex')              

            ];

           

            if(input('password')){

                $data['password']=md5(input('password'));

            } else {

                $data['password']=$admins['password'];

            }


            $validate = validate('Admin');  


            if(!$validate->scene('edit')->check($data)){

                $this->error($validate->getError());

            }


            $save = db('admin')->where('id',$id)->update($data); 


            if($save){ 

                return json($data);

                //return;

            }else{

                $data2 = 404;

                return $this->ajaxReturn($data2,'修改失败',0);

            } 

            return;

        }

        

        $this->assign('admins',$admins);

        return $this->fetch('admin-edit');

    }



Js部分:

<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script> 

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script> 

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript">

 

$(function(){

    $('.skin-minimal input').iCheck({

        checkboxClass: 'icheckbox-blue',

        radioClass: 'iradio-blue',

        increaseArea: '20%'

    });

    

    $("#form-admin-add").validate({

        //验证规则

        rules:{

            username:{

                required:true,

                minlength:4,

                maxlength:16

            },

            uname:{

                required:true,

                minlength:4,

                maxlength:16

            },

            password:{

                required:true,

            },

            password2:{

                required:true,

                equalTo:'#password'

            },

            usertype:{

                required:true,

                number:true

            },

            email:{

                required:true,

                email:true

            },

            signature:{

                required:true,

                minlength:4,

                maxlength:100

            },

        },

        //验证设置

        onkeyup:true, //在 keyup 时不验证

        focusCleanup:true,

        success:"valid",

        submitHandler:function(form){

            $(form).ajaxSubmit({

                type: 'post',

                dataType: "json",

                url: "{:url('admin/admin_edit')}",

                success: function(data){

                    //alert(data);

                    layer.msg('修改成功!', {icon:1,time:1000}, function(){

                        var index = parent.layer.getFrameIndex(window.name);

                        parent.location.reload(); //刷新父页面

                        parent.layer.close(index);

                    });

                },

                error: function(XmlHttpRequest, textStatus, errorThrown){

                    layer.msg('error!',{icon:1,time:1000});

                }

            });

        }

    });


});

</script> 


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!