Skip to content Skip to sidebar Skip to footer

Javascript Array Not Initialized

I have a problem with javascript array when passing into another object array. I have tried everything I came out on net, but nothing is working. Problem is in line when fetching

Solution 1:

Ajax calls are asynchronous... this mean the data will be set before getting any response from your ajax request.

In order to fix this, you need to create your data in the ajax success callback function:

$.ajax({
    success: function (data) {
        $.each(data, function (k, v) {
            labelValues.push(v.opis);
            dataValues.push(v.potroseno_tekucine);
        });
        var data2 = {
          labels: labelValues,
          //...
        };
        //Insert your logic here to handle data2
    }
});

Post a Comment for "Javascript Array Not Initialized"