I will explain what I want to do, I from a file js create an array in which I will generate associative indexes (if that is how you can call them). After creating the array I try to send it through ajax to a php file, but when trying to receive the array it comes empty, I tried with JSON.stringify () before sending it and receiving it with a json_decode () but it did not work for me.
This is my code in js (diculpen if my code is something murky I'm still a novice in this, thank you)
var array_datos = [];
function llenarArreglo()
{
if(array_datos[unidad] === undefined) array_datos[unidad] = [];
if(array_datos[unidad]['Apartado'] === undefined) array_datos[unidad]['Apartado'] = [];
if(array_datos[unidad]['Apartado']['Fecha'] === undefined) array_datos[unidad]['Apartado']['Fecha'] = [];
if(array_datos[unidad]['Apartado']['Valor'] === undefined) array_datos[unidad]['Apartado']['Valor'] = [];
if(array_datos[unidad]['Apartado']['Fecha'][cont] === undefined)
{
array_datos[unidad]['Apartado']['Fecha'][cont] = fecha;
}
if(array_datos[unidad]['Apartado']['Valor'][cont] === undefined)
{
array_datos[unidad]['Apartado']['Valor'][cont] = valor;
}
};
$('#boton_guardar').on('click', function(){
var obj = $.ajax({
method: 'POST',
url: 'procesar.php',
data: {
evento: 'guardar',
datos: array_datos
},
beforeSend: function(){
}
}).done(function(data){
console.log(data);
});
});
and in PHP I get it this way
$evento = filter_input('INPUT_POST', 'evento');
switch($evento)
{
case 'guardar':
$datos = filter_input('INPUT_POST', 'datos', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
print_r($datos);
break;
}