I have problems to show the information filtered in a POST and I do not know what the error is, I am following the indications of the official page of Jquery to use the POST but when trying to show the data in the datatable I only see an object : Object, help please.
Thanks !!
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
<title>Prueba datatable</title>
<script>
$(document).ready(function(){
var table = $.post( "http://jsonplaceholder.typicode.com/posts",{userId:"3"}, function( data ) {
table.done(function( data ) {
alert( "Data Loaded: " + data );
});
alert( "success" );
table.done(function() {
alert( "second success" );
})
table.fail(function() {
alert( "error" );
})
table.always(function() {
alert( "finished" );
});
$('#data-table').DataTable({
"data" : data,
columns : [
{"data" : "userId"},
{"data" : "id"},
{"data" : "title"},
{"data" : "body"}
]
});
});
});
</script>
</head>
<body>
<table id="data-table" class="table table-bordered" width="100%">
<thead>
<tr>
<th>userId</th>
<th>id</th>
<th>title</th>
<th>body</th>
</tr>
</thead>
</table>
</body>
</html>