1
Greetings!! I’m trying to do something I don’t know if it’s possible. I have a table in an html page, which I took and turned into an array of objects that apart from Ajax send the same array to another php page that later I will visualize it in table form.
//Envia para o php
function mandar_tabela() {
var indices = [];
//Pega os indices
$('#tabela-preços thead tr th').each(function() {
indices.push($(this).text());
});
var arrayItens = [];
//Pecorre todos os produtos
$('#tabela-preços tbody tr').each(function(index) {
var obj = {};
//Controle o objeto
$(this).find('td').each(function(index) {
obj[indices[index]] = $(this).text();
});
//Adiciona no arrray de objetos
arrayItens.push(obj);
});
//Mostra dados pegos no console
console.log(arrayItens);
//Envia para o php
$.ajax({
type: "POST",
url: "imprimirfatura1.php",
data: arrayItens,
success: function() {
alert('Deu tudo certo');
},
});
}
However, when it comes to receiving in php page I can’t even see the array of sent objects. When I open the page printtable.php I find absolutely nothing. I tried to use the POST method but could not, six the code piece of the page printtable.php next:
<?php
$array[] = $_POST['arrayItem'];
$pagina="<!DOCTYPE html>
<html lang='en'>
[...]
How do I receive this object array with ajax, and view on the page printtable.php
if you make a
$.ajax
will not leave the current page, should make a Submit to the other tab, and put the array for example in a field input type Hidden so you can request on the other page– Ricardo Pontual
Ricardo Pontual, I didn’t notice. I just updated the question, putting all the javascript function
– Edylsom Combane
a request ajax returns to the same page, so I figured want to send the data to another page and from the other page create the table is this?
– Ricardo Pontual
That’s right Ricardo, I want to send the data to another page.
– Edylsom Combane
because then the way to do this is to put everything in a form tag, for example
<form action='imprimirtabela.php'>...aqui vão todos os campos, </form>
and put the result of the array in a field within the tag form. If you have questions let us know– Ricardo Pontual
So with that, I would have to put my table inside a form, then convert it into an array, right?
– Edylsom Combane
I put in an answer to make it clearer
– Ricardo Pontual