I'm trying to consume an api and then display it in a table via ajax with Jquery's DataTables Plugin but I'm not getting the table to load with the data
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.min.js"></script>
<script src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
> este es el script que deberia consumir el json
<script>
$('#tabla').dataTable({
ajax: {
cache: true,
url: `https://my-json-server.typicode.com/AldoArevalo%20/repoaldo/aguinaldo`,
dataSrc: 'data.results'
},
columns: [{
"data": "AACAA_PADR"
}, {
"render": function(v, t, data) {
return `<img width="100" src="${ data.thumbnail.extension}"/>`;
}
}, {
"data": "AACAA_BANC"
}, {
"data": "AACAA_CEDU"
}]
});
</script>
<!DOCTYPE html>
<html lang="es">
<head>
</head>
<body>
<table id="tabla" class="display" style="width:100%"></table>
</body>
</html>
Directly entering the provided URL, the following result is obtained:
There isn't a property
results
, it's just useddata
and there isn't a property eitherthumbnail
, so it throws an error.