hello to all I have the following form in which I add products and when clicking on add they are stored in the table as in the image, As you can see in the image I have 3 products and when clicking on preview what it does is store all the records of the table in an array
this is the code
JQuery (ajax)
$('#btnbtn').on('click',function(){
/*(nose si es la mejor manera de almacenar los datos de mi tabla en un array,
si alguien sabe una mejor manera ,le estaria muy agradecido) ↓*/
var datosArray=new Array();
$('#tablaProductosIngresados > #tablaPI').each(function () {
var codigoArray = $(this).find('td').eq(0).html();
var descripcionArray = $(this).find('td').eq(1).html();
var unidadMedidaArray = $(this).find('td').eq(2).html();
var PrecioUniArray= $(this).find('td').eq(3).html();
var cantidadArray = $(this).find('td').eq(4).html();
var descuentoArray = $(this).find('td').eq(5).html();
var totalArray = $(this).find('td').eq(6).html();
var itemArray = $(this).find('td').eq(8).html();
var tipoExistenciaArray = $(this).find('td').eq(9).html();
var fechaVigenciaArray = $(this).find('td').eq(10).html();
valor=new Array(codigoArray, descripcionArray, unidadMedidaArray,PrecioUniArray,cantidadArray,descuentoArray,totalArray,itemArray,tipoExistenciaArray,fechaVigenciaArray);
datosArray.push(valor);
var jsonString = JSON.stringify(valor);
// console.log(jsonString);
$.ajax({
url:'insertVistaPrevia.php',
type:'POST',
data:{btnbtn:jsonString},
cache: false,
success:function(data){
console.log(data);
}
});
return false;
});
})
and so I receive them in my php code
php
<?php
$data = json_decode($_POST['btnbtn']);
foreach ($data as $datos) {
echo $datos;
}?>
my problem is that it only shows me the first record of my table
I do not know how to put my code of the table since columns are generated as you click on a button to add .....
I've searched and everyone says it's done with "" "JSON.stringify" ""
but it does not come out, I hope you help me