• ajax省市县三级联动



    js事件

        $('#ProvinceId').change(function(){
                var parentId = $(this).val();
                $.ajax({
                    url: '{sh::U("OpenStore/ajax","todo=getCity")}',
                    type: 'POST',
                    data: 'parentId='+parentId,
                    dataType:'json',
                    success: function(json) {
                        if (json.status == 1) {
                            var optionCity = "<option value=''>==请选择==</option>";
                            $.each(json.info,function(i,n){
                                optionCity += "<option value="+i+">" + n + "</option>";
                            });
                            var optionCounty = "<option value=''>==请选择==</option>";
                            // 重置市、县
                            $('#CityId').html(optionCity).val('');
                            $('#CountyId').html(optionCounty).val('');
                        } else {
                            layer.msg('获取数据异常');
                        }
                    }
                });
            });
    
            $('#CityId').change(function(){
                var parentId = $(this).val();
                $.ajax({
                    url: '{sh::U("OpenStore/ajax","todo=getCounty")}',
                    type: 'POST',
                    data: 'parentId='+parentId,
                    dataType:'json',
                    success: function(json) {
                        if (json.status == 1) {
                            var optionCounty = "<option value=''>==请选择==</option>";
                            $.each(json.info,function(i,n){
                                optionCounty += "<option value="+i+">" + n + "</option>";
                            });
                            // 重置县
                            $('#CountyId').html(optionCounty).val('');
                        } else {
                            layer.msg('获取数据异常');
                        }
                    }
                });
                
            });
    

    ajax

        public function ajax() {
            $todo = $this->_request('todo','trim');
            $data = array('status'=>0,'msg'=>'','info'=>array());
            switch ($todo) {
                case 'getCity':
                    $parentId = $this->_post('parentId','trim');
                    $getAreaData = $this->integral->getArea('2',$parentId); // 获取市
                    if ($getAreaData['status'] == 1) {
                        $citys = $getAreaData['CustomProperties'];
                        $data['status'] = 1;
                        $data['info'] = $citys;
                        $data['msg'] = '获取成功';
                    } else {
                        $data['status'] = 9;
                        $data['msg'] = '获取异常';
                    }
    
                    $this->ajaxReturn($data,'JSON');
                    break;
                
                case 'getCounty':
                    $parentId = $this->_post('parentId','trim');
                    $getAreaData = $this->integral->getArea('3',$parentId); // 获取市
                    if ($getAreaData['status'] == 1) {
                        $countys = $getAreaData['CustomProperties'];
                        $data['status'] = 1;
                        $data['info'] = $countys;
                        $data['msg'] = '获取成功';
                    } else {
                        $data['status'] = 9;
                        $data['msg'] = '获取异常';
                    }
                    
                    $this->ajaxReturn($data,'JSON');
                    break;
                default:
                    # code...
                    break;
            }
        }
    
  • 相关阅读:
    ulimit c unlimited
    2021.9.28 Sqoop
    2021.9.30 利用sqoop将hive数据导出到mysql
    2021.10.2 建造者模式
    111每日博客
    1029每日博客
    112每日博客
    113每日博客
    Panda 交易所视点观察!区块链金融应用迎新规,哪些版块受影响?
    c# 读取word
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/5646706.html
Copyright © 2020-2023  润新知