Reputation: 73
My controller:
function index()
{
return view('student.ajaxdata');
}
function getdata()
{
$student = Student::select('first_name', 'last_name', 'Age', 'Address', 'Grade_Level');
return Datatables::of($student)->make(true);
}
jQuery code:
$(document).ready(function() {
$('$students_table').Datatables({
"processing" : true;
"serverside" : true;
"ajax" : "{{route('ajaxdata.getdata')}}"
"column":[
{"data" : "first_name"},
{"data" : "last_name"},
{"data" : "Age"},
{"data" : "Address"},
{"data" : "Grade_Level"}
]
});
})
It supposed to fetch data and put in the table but in my case there's no error or anything but when i go to the view page there's no data was fetch.
Upvotes: 0
Views: 1920
Reputation: 65
Verify if Datatables::of($student)->make(true)
returns a Json array.
Like this:
dd(Datatables::of($student)->make(true));
Upvotes: 0
Reputation: 1745
The issue is your JS part.
$('$students_table')
It should be $('#students_table')
with a hash.
Upvotes: 1