0

I need to access an object that is created in the ajax function to proceed with a method...

$.ajax({
    type: "POST",
    url: '../GeneralManager/Sales/DAOs/CompPSMCQuery.php',
    data: {compRangeY1: rangeY1,
        compRangeY2: rangeY2,
        compRangeM1: rangeM1,
        compRangeM2: rangeM2},
    success: function (data)
    {
        var arr = [];
        arr = JSON.parse(data);
        var asList = [], tcList = [], acList = [], yearList = [], monthList = [];
        for (var x = 0; x < arr.length; x++) {
            asList.push(Number(arr[x].actualSales.replace(/[^0-9\.]+/g, "")));
            tcList.push(Number(arr[x].transactionCount.replace(/[^0-9\.]+/g, "")));
            acList.push(Number(arr[x].averageCheck.replace(/[^0-9\.]+/g, "")));
            yearList.push(Number(arr[x].calYearNum.replace(/[^0-9\.]+/g, "")));
            monthList.push(Number(arr[x].calMonthNum.replace(/[^0-9\.]+/g, "")));
        }

        obj1 = {
            name: 'Period 1',
            asList: asList,
            tcList: tcList,
            acList: acList,
            yearList: yearList,
            monthList: monthList
        };
    }
});

You see I need to access obj1 outside the ajax...

  • Define it outside the ajax. – PitaJ Oct 24 '14 at 02:05
  • var obj1 = new Object(); I already did but when I access the arrays I stored in them it still responds undefined – Miguel Elisan Oct 24 '14 at 02:31
  • You can't expect it to be set directly after the AJAX call because AJAX is asynchronous, meaning you will have to put all code dependent on results of the AJAX call in the callback. – PitaJ Oct 24 '14 at 03:39

0 Answers0