我为重装数据表的jquery-datatable定义了“ajax”属性 但是当jq-datatable向控制器发送请求时,console.log会显示“500内部服务器错误”
jquery的:
$(document).ready(function () {
var table = $('#rules_table').DataTable({
"ajax" : {
'url': "{{route('rules.data')}}",
'type': 'POST'
},
select: {
style: 'single'
}
});
$('#reload').on('click',function () {
table.ajax.reload(null,false);
})
});
路线:
Route::resource('rules','Rules\RulesController');
Route::post('rules/data', [
'as' => 'rules.data', 'uses' => 'rules\RulesController@data'
]);
规则控制器
public function index(Request $request)
{
$rules = Rules::all();
return view('rules/index', compact('rules', $rules));
}
public function data() //this function is resposible for ajax request
{
$rules = Rules::all();
return response()->json([$rules]);
}