Pass the variable as a data source
Pass the variable as a data source
Hi,
I am forced to make an ajax call which gives me a bool value that i go to check.
If it is true I create the datatable in js.
Example:
$.ajax({
type: "POST",
url: "myapi.php",
data: {"fl": fl},
dataType: "json",
success: function(data){
if (data.success && data.ln=='ok'){
$(document).ready(function() {
$("#tablefdi").DataTable({
"scrollY": "431px",
"scrollX": "true",
"autoWidth": false,
dataSrc: data.data,
"columns": [
{
"orderable": false,
"data": null,
"defaultContent": ""
},
{ "data": "id" },
{ "data": "sn" },
{ "data": "na" },
{ "data": "tx" },
],
"order": [[2, "asc"]]
});
});
}else{
alert(data.error);
}
});
The data is not loaded. Why?
I tried running the $.parseJSON i got syntax error... :-/
If i make the same call directly from datatable, the data is loaded correctly
Thanks...
Replies
I solved ... with "data": data.data, and not dataSrc: data.data
regards...