How can I get an arrangement made in jquery?


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(){


and in PHP I get it this way

$evento = filter_input('INPUT_POST', 'evento');
    case 'guardar':
        $datos = filter_input('INPUT_POST', 'datos', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
asked by Escanor666 31.07.2018 в 06:46

1 answer


Thank you all for your support and amenadiel thank you for your answer, that was the one that gave me the key to solve my problem, you were right, what happens is that I was declaring as array my main variable and to go initializing the properties I put them as an array as well, change everything to {} and I was able to obtain the necessary data. Thank you very much

Greetings !!!

answered by 31.07.2018 в 18:45