thinkphp3.2--点击某个class 利用jQuery从后台获取数据填到表格

html代码:

 <div class="modal fade bs-example-modal-lg" id="myModal-jjxx" tabindex="-1" role="dialog"
                                     aria-labelledby="myModalLabel-jjxx" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content" >
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"
                                                        aria-hidden="true">&times;
                                                </button>
                                                <h4 class="modal-title">机架信息列表</h4>
                                            </div>
                                            <div class="modal-body">
                                                <table class="table table-striped table-bordered table-hover">
                                                    <thead>
                                                    <tr class="active">
                                                        <th style="text-align: center;">机架信息ID</th>
                                                        <th style="text-align: center;">机架/机位名称</th>
                                                        <th style="text-align: center;">使用类型</th>
                                                        <th style="text-align: center;">分配状态</th>
                                                        <th style="text-align: center;">占用状态</th>
                                                    </tr>

                                                    </thead>
                                                    <tbody id="info_frame">
                                                    </tbody>
                                                </table>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                                </button>
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal -->
                                </div>

js代码:

$(".show_frameInfo").click(function (){
        var house_id = $(this).parents('tr').children('td:eq(0)').html();
        $.ajax({
            type: "get",
            url: "__URL__/frame_info",
            data: {'house_id':house_id},
            dataType:'json',
            success: function(data){
                if (data) {
                    $("#info_frame").children().remove();
                    $.each(data.data, function(index, value) {
                        $("<tr><td style='text-align:center;'>" + value.id + "</td><td style='text-align:center;'>" + value.frame_name +"</td><td style='text-align:center;'>" + value.usertype +"</td><td style='text-align:center;'>" + value.distribution +"</td><td style='text-align:center;'>" + value.occupancy +"</td></tr>").appendTo($("#info_frame"));
                    });
                }
            }
        })
    });

PHP代码:

public function frame_info(){
      if(I('house_id')!=''){
        $house_id = I('house_id');
        $result = M('basic_frame')->where(array('house_id'=>$house_id,'status'=>array('neq',3)))->select();
        foreach ($result as $key => $value) {
          $result[$key]['usertype'] = $this->info_value('usertype',$value['usertype']);
          $result[$key]['distribution'] = $this->info_value('distribution',$value['distribution']);
          $result[$key]['occupancy'] = $this->info_value('occupancy',$value['occupancy']);
          $result[$key]['is_special'] = $this->info_value('is_special',$value['is_special']);
        }
      }
        $this->ajaxReturn(array('data'=>$result));
    }

猜你喜欢

转载自blog.csdn.net/qq_19809797/article/details/81667002