I always got this error. And I don't know what is wrong with my code. When I dd
the data, It shows me the correct one. Does anyone know what should I do about this? Thanks in advance
Error:
DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7
My Ajax code:
@section('scripts')
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
var id = {{ $item->id }};
$(document).ready(function() {
$('#example').DataTable( {
'processing': false,
'serverSide': true,
'ajax': "{{route('admin.finances.edit',"+id+")}}",
'column': [
{'data': 'id'},
{'data': 'description'},
{'data': 'amount'},
{'data': 'date'}
]
});
});
</script>
@show
Controller:
public function edit($id)
{
$item = User::where('id', $id)->first();
$x = \DB::table('finances')
->where('finances.user_id', $id)
->orderBy('finances.id' ,'DESC')
->get()->toArray();
$details = Datatables::of($x)->make(true);
// $results = DataTables::of(Payment::query())->make(true);
// dd($details);
return view('admin.pages.finances.show',[
'mnuname' => $this->page_title,
'page_title' => $this->page_title,
'item' => $item,
'details' => $details,
]);
}
Route
Route::get('finances/{id}', 'FinancesController@edit')
->name('admin.finances.edit');
when i dd($details)
JsonResponse {#568 ▼
#data: "{"draw":0,"recordsTotal":8,"recordsFiltered":8,"data":[{"id":"16","school_id":"1","user_id":"11","amount":"85454","description":"Pinakalatest","date":"2019-11-1 ▶"
#callback: null
#encodingOptions: 0
+headers: ResponseHeaderBag {#567 ▶}
#content: "{"draw":0,"recordsTotal":8,"recordsFiltered":8,"data":[{"id":"16","school_id":"1","user_id":"11","amount":"85454","description":"Pinakalatest","date":"2019-11-1 ▶"
#version: "1.0"
#statusCode: 200
#statusText: "OK"
#charset: null
+original: array:5 [▼
"draw" => 0
"recordsTotal" => 8
"recordsFiltered" => 8
"data" => array:8 [▶]
"input" => []
]
+exception: null