datatable sAjaxSource - the echo return includes html
datatable sAjaxSource - the echo return includes html
was
Posts: 1Questions: 1Answers: 0
my js file:
$(document).ready(function() {
$('#table_supp').DataTable({
//data:data_prod,
responsive: true,
"bProcessing": true,
"sAjaxSource": "form_supp.php",
"aoColumns":[
{ mData: 'Product' }
]
});
} );
and im my phph file i have also an html, so it returns me also an html, and i don't how to handl it.
this is how i return the data
</head>
<body >
<div class="container tables-container">
<div>
<table id="table_supp" class="display" cellspacing="0" width="90%">
<thead>
<tr>
<th>Product</th>
<th>New proposal</th>
<?php
$data_to_datatable=array(
array('Product'=>'check it')
);
$results = array(
"sEcho" => 1,
"iTotalRecords" => count($data_to_datatable),
"iTotalDisplayRecords" => count($data_to_datatable),
"aaData"=>$data_to_datatable);
echo json_encode($results);
?>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
and it shows this error : "DataTables warning: table id=table_supp - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/"
and this is the response
please any help, i'm new in datatable
This discussion has been closed.
Answers
As the DataTables error message states, DataTables expects JSON in response to an Ajax request - not a full HTML page. More detail can be found in the manual about how to use JSON with DataTables.
Allan