How to make a for ajax requests?

2

Why does not this work? I mean it shows twice my alert and then for, with the value of aux_count being 17.

for(var i = aux_cont; i > 0; i++ ){
    var eval_data = eval(obj_grafico[aux_cont].series);

    alert(aux_cont);
    alert(i);

    $.ajax({
        type:"POST",
        url:"../../tmp/cria_json_pan_servidor.php",
        data:{
            montante_y:obj_grafico[i].montante_y,
            tickInterval_y:obj_grafico[i].tickInterval_y,
            min_y:obj_grafico[i].min_y,
            max_y:obj_grafico[i].max_y,
            min_x:obj_grafico[i].min_x,
            max_x:obj_grafico[i].max_x,
            tickInterval_x:obj_grafico[i].tickInterval_x,
            filename:obj_grafico[i].filename,
        },
        cache:false
    });
}

below how do I define the values of my object:

obj_grafico[aux_cont] = {

        montante_y: montante_y,
        tickInterval: intervalo_y,
        min_y: min_y,
        max_y: max_y,
        min_x: min_x,
        max_x: max_x,
        tickInterval: intervalo_x,
        tickAmount: montante_x,
        series: seriesOptions,
        filename: hostname

    }
    
asked by anonymous 03.01.2018 / 18:59

1 answer

1

I think your is wrong ...
I believe that the value of aux_cont is already 17 before the for
Please try the following:

for(var i = 0; i < aux_cont; i++ ){
    var eval_data = eval(obj_grafico[i].series);

    alert(aux_cont);
    alert(i);

    $.ajax({
        type:"POST",
        url:"../../tmp/cria_json_pan_servidor.php",
        data:{
            montante_y:obj_grafico[i].montante_y,
            tickInterval_y:obj_grafico[i].tickInterval_y,
            min_y:obj_grafico[i].min_y,
            max_y:obj_grafico[i].max_y,
            min_x:obj_grafico[i].min_x,
            max_x:obj_grafico[i].max_x,
            tickInterval_x:obj_grafico[i].tickInterval_x,
            filename:obj_grafico[i].filename,
        },
        cache:false
    });
}
    
03.01.2018 / 19:17