Good afternoon, guys. I'm trying to pass an array that I retrieve from a JSON to DB, but I'm not able to identify Array objects, I think I'm doing something wrong, I've done some tests with foreach but I did not succeed, follow the cod's.
HTML
<?php include('header.php'); ?>
<script type="text/javascript" src="script/script.js"></script>
<title>DataTable</title>
<style>
tfoot input {
width: 100%;
padding: 0;
box-sizing: border-box;
color: #FFFFFF;
}
tfoot {
display: table-footer-group;
}
</style>
<?php include('container.php'); ?>
<div class="container">
<h2>DataTable</h2>
<div class="row">
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>Data</th>
<th>Horário</th>
<th>Nº Telefone</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th class="selectedDate" id="1">Data</th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
</div>
</div>
<?php include('footer.php'); ?>
script.js
// _START_ DataTable
var table = $('#example').DataTable({
"bProcessing": true,
"sAjaxSource": "data.php",
"bPaginate": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"autoWidth": true,
"aoColumns": [
{mData: [0]},
{type: 'date-br',
targets: 1},
{ "orderable": false, "targets": 2 }, // remove a ordenação
{ "orderable": false, "targets": 3 },
]
});
// função para retornar o dados da tela em json
setInterval(function () {
var table3 = $('#example').tableToJSON();
var request = $.ajax({
method: "POST",
url: "teste.php",
data: { array: table3},
dataType: "html"
})
request.done(function(resposta) {
//resposta servidor
console.log(resposta)
});
}, 6000); // está em segundos
test.php
<?php
$array = ($_POST['array']);
print_r($array);
Array
Array
(
[0] => Array
(
[ID] =>
[Data] =>
[Horário] =>
[Nº Telefone] =>
)
[1] => Array
(
[ID] => 8010
[Data] => 27/12/2017
[Horário] => 14:58:27
[Nº Telefone] => 1231530337
)
[2] => Array
(
[ID] => 8010
[Data] => 27/12/2017
[Horário] => 14:56:52
[Nº Telefone] => 1231530337
)
)