I'm trying to show some data on a Datatable. The data is called from an Ajax request and the response is a Json array, it looks like this:
[{"item": "one", "price": 22, "status": "free"}, {"item": "two", "price": 15, "status": "taken"}]
And here is my request:
<script>
$(document).ready(function() {
$('mytable').DataTable( {
"ajax": "myurl",
"dataType": 'json',
"dataSrc": '',
"columns": [
{"data": "item" },
{"data": "price" },
{"data": "status"},
]
} );
} );
</script>
And here is my HTML:
<table id="mytable" class="display" style="width:100%">
<thead>
<tr>
<th>ITEM</th>
<th>PRICE</th>
<th>STATUS</th>
</tr>
</thead>
</table>
The issue is that the data is not being shown on the table. I think the problem happens when Datatables tries to handle my JSON data, since i'm getting this error on my console:
Uncaught TypeError: Cannot read property 'length' of undefined