Data is undefined
Data is undefined
![Miko55](https://secure.gravatar.com/avatar/344e14314c39fe94900dc0dd5810cda2/?default=https%3A%2F%2Fvanillicon.com%2F344e14314c39fe94900dc0dd5810cda2_200.png&rating=g&size=120)
I get this json back from my controller:
[
{"username":"test3","points":62,"sportName":"Basketball"},
{"username":"test2","points":55,"sportName":"Football"},
{"username":"Test1","points":32,"sportName":"Basketball"},
{"username":"miko55","points":25,"sportName":"Football"},
]
And this is my code:
var table=$('#users-table').DataTable({
processing: true,
serverSide: true,
"ajax": {
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: '{!! route('get.leaderboardsData') !!}',
},
columns: [
{ data: 'sportName', name: 'sportName' },
{ data: 'username', name: 'user_id' },
{ data: 'points', name: 'points' },
]
});
I think problem is that current json response doesn't have date around an array, if I am right, how can I fix that. I am using laravel
This discussion has been closed.
Answers
You can use
ajax.dataSrc
to tell Datatables where to find the data. The second example is what you want.Kevin