datatable sAjaxSource - the echo return includes html
datatable sAjaxSource - the echo return includes html
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);
and this is the response
please any help, i'm new in datatable
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