显示数据库中数据表中的数据

时间:2018-11-05 13:26:04

标签: jquery ajax datatables laravel-5.4

  

我想在数据表中显示数据,但显示所有null   值

     

控制器:

 public function ex(Request $request){
            $table =  \DB::table('company')->select('name','type','address','city','email','description')->get();
            return $table;
        }
  

display.blade.php

<body>
<button id="mybutton">Click Me</button><br><br><br>
<table border="1px" id="imp" class="table table-striped table-bordered" style="width:100%">
    <thead>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Address</th>
        <th>City</th>
        <th>Email</th>
        <th>Description</th>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
    $(document).ready(function () {
        $("#mybutton").click(function(){
            $('#imp').DataTable({
                "processing": true,
                "serverSide":true,
                "ajax": {"url":"display"},
                "columns": [
                    { "data": "name" },
                    { "data": "type"},
                    { "data": "address" },
                    { "data": "city" },
                    { "data": "email" },
                    { "data": "description" }
                ]
            });
        });
        });

</script>
</body>
  

我想以表格形式在表格中显示数据   页   同时做dd();数据采用JSON格式,但显示在html上   页面

1 个答案:

答案 0 :(得分:0)

You missed the dataSrc to pass after the ajax URL.
<script>
        $(document).ready(function () {
            $("#mybutton").click(function(){
                $('#imp').DataTable({
                    "processing": true,
                    "serverSide":true,
                    "ajax": {"url":"display", dataSrc:''},
                    "columns": [
                        { "data": "name" },
                        { "data": "type"},
                        { "data": "address" },
                        { "data": "city" },
                        { "data": "email" },
                        { "data": "description" }
                    ]
                });
            });
        });

    </script>