Some issue with ajax connection
Some issue with ajax connection
paolo.b
Posts: 2Questions: 1Answers: 0
Hi, I've have some problem with the ajax connection.
I make it with the API rest ( work with json stored in a variable, everything works fine)
that's my code:
//other stuff
$(document).ready(function(){
var table = $('#datatables').DataTable({
"ajax": "../id/activities",
"columns": [
{ "data": "activityid" },
{ "data": "activityTitle" },
{ "data": "color" }
],
"order": [[1, 'asc']]
});
//other stuff
the REST responds with a little bit tricky nested json
an example:
{
"result": "OK",
"exception": "",
"return": {
"results": [
{
"activityid": "123",
"activityTitle": "do list",
"color": "custom1"
}
]
}
}
That's dont work !
Only with that works fine:
$(document).ready(function(){
var jsonReply = <?php echo json_encode($jsonResults) ?> ;
var table = $('#datatables').DataTable({
"data": jsonReply.results,
"columns": [
{ "data": "activityTitle" },
{ "data": "activityid" },
{ "data": "color" }
],
"order": [[1, 'asc']]
});
//other stuff
Can someone explain?
TIA
Paolo
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use
ajax.dataSrc
to tell DataTables where to get the json data from (assuming you are using DataTables'ajax
option to get the data - like you do in the first code block).Allan
@allan You are my MAESTRO!
Thanks a lot for the solution, you make my day !
I owe you a beer!