0

1.a.blade.php

submit a form 
action="a_1"
  1. 网页.php

    路线::get('a_1', 'CodoController@a_1');

  2. CodoController

     public function a_1(Request $request)
    {
         $search = $request->all();
         $result=DB:query()
                 ->select...
                 ->get();
    
      return view(b_1)
         ->with('result',$result);
     }
    
  3. b_1.blade.php

       <table class="table table-bordered" id="users-table">
            <thead>
                <tr>
                    <td>Id</td>
                    <td>Name</td>
                 </tr>
            </thead>
        </table>
    
    
    <script>
    $(function() {
        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax:?????<-----How to write this place to receive the $result collection?
            columns: [
                { data: 'id', name: 'id' },
                { data: 'name', name: 'name' }
                ......
            ]
        });
    });
    

我不明白这个例子 在此处输入图像描述

是 Route:: 类吗?可以在控制器上使用吗?以及如何在 ajax 上编写脚本:???? 地方。我尝试将这些写入 Codocontroller

use DataTables;

public function a_1(Request $request)
{
     $search = $request->all();
     $result=DB:query()
             ->select...
             ->get();

Route::get('b_1', function() {

      return DataTables::collection($result)->toJson();
});

路由可以写在控制器上吗?我得到的错误是

Class Route cannot find.

如果它是正确的用法。

b_1.blade.php 视图下面的脚本如何接收集合?

    <script>
    $(function() {
        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax:?????<-----How to write this place to receive the $result collection?
            columns: [
                { data: 'id', name: 'id' },
                { data: 'name', name: 'name' }
                ......
            ]
        });
    });

</script>
4

1 回答 1

0

ajax属性中,基本上您只需设置ajax call参数即可获取您的信息。

例如

ajax: {
    url: my_url_path,
    data: function(d){
        d.param1 = some_val_1
        d.param2 = some_val_2
    },
}

whereURL是获取 JSON 数据的路径,并且data是请求参数。

上面的示例将创建一个请求 URL,如下所示:

http://my_url_path?param1=some_val_1&param2=some_val_2

在您的情况下,它将类似于:

ajax: {
    url: '{{url("user-data")}}'
}
于 2018-04-19T12:56:05.890 回答