【发布时间】:2017-08-17 12:44:10
【问题描述】:
我在 laravel 中使用了 Datatables 并收到以下警告消息:
DataTables 警告:表 id=DataTables_Table_0 - Ajax 错误。更多 有关此错误的信息,请参阅http://datatables.net/tn/7
我无法从数据库中的表中获取 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>
我哪里做错了?我该如何解决这个问题?
【问题讨论】:
标签: php mysql ajax laravel datatable