DataTables警告:table id = DataTables_Table_0 - Ajax错误

时间:2017-08-17 12:44:11

标签: php mysql ajax laravel datatable

我在laravel中使用了Datatables并收到以下警告信息:

  

DataTables警告:table id = DataTables_Table_0 - Ajax错误。更多   有关此错误的信息,请参阅this

我无法从数据库中的表中获取JSON数据

这是我的控制器

 public function data()
    {
       // return Datatables::of(Employee::select("*"))->make(true);
        $users = Employee::select(['id','employee_name','gender', 'join_date', 'identity_no', 'birthdate', 'idaddress']);
        return Datatables::of($users)->make();
    }

路线

Route::any("data", "EmployeeController@data");

模型

 public function attributeLabels()
    {
        return [
            "id" => "id",
            "nik" => "Nik",
            "employee_name" => "Nama Pegawai",
            "gender" => "Jenis kelamin",
            "join_date" => "Tgl bergabung",
            "identity_no" => "No identitas",
            "birthdate" => "Tgl Lahir",
            "idaddress" => "Alamat",
        ];
    }

<table class="table table-bordered" datatable="{{ url("hr/employee/data") }}">
    <thead>
      <tr>
        <th dt-field="id"> {{ $model->label("id") }} </th>
        <th dt-field="nik"> {{ $model->label("nik") }} </th>
        <th dt-field="employee_name"> {{ $model->label("employee_name") }} </th>
        <th dt-field="gender"> {{ $model->label("gender") }} </th>
        <th dt-field="join_date"> {{ $model->label("join_date") }} </th>
        <th dt-field="identity_no"> {{ $model->label("identity_no") }} </th>
        <th dt-field="birthdate"> {{ $model->label("birthdate") }} </th>
        <th dt-field="idaddress"> {{ $model->label("idaddress") }} </th>
        <th dt-col="#dt-action" sort="false" search="false"> </th>
      </tr>
    </thead>

我在哪里做错了?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我认为您错过了在您的选择查询中选择nik。如果这样做,它应该工作。当数据表中缺少任何字段时,它会抛出此错误。