title: Sending Array to AJAX and Accessing Passed Data to Controller in Codeigniter
body: <p>I'm trying to get the table data and store it in an array and pass it in the controller so i can write in PHP excel. I've tried using other data and it worked. Now when I try to use this my excel file is empty.</p>
  
  <p>Here is my Javascript code</p>
  
  <pre><code>    var TableData = new Array();
      $('#tblmonthlydues tr').each(function(row, tr){
          TableData[row] = {
              "amortid" : $(tr).find('td:eq(0)').text()
              , "duedate" :$(tr).find('td:eq(1)').text()
              , "customername" : $(tr).find('td:eq(2)').text()
              , "lotdesc" : $(tr).find('td:eq(3)').text()
              , "daysdue" : $(tr).find('td:eq(4)').text()
              , "amountdue" : $(tr).find('td:eq(5)').text()
              , "amortdue" : $(tr).find('td:eq(6)').text()
              , "surcharge" : $(tr).find('td:eq(7)').text()
              , "vat" : $(tr).find('td:eq(8)').text()
              , "ips" : $(tr).find('td:eq(9)').text()
              , "interest" : $(tr).find('td:eq(10)').text()
              , "principal" : $(tr).find('td:eq(11)').text()
              , "payments" : $(tr).find('td:eq(12)').text()
          }
      });
      TableData.shift();
      var data = JSON.stringify(TableData);
      data = data.substring(0, data.length - 1).substring(1, data.length);
      console.log(data);
  
      $.ajax({
          type: "POST",
          url:  baseurl + "collection/get_monthly_dues_report",
          data: {'data':data},
          success: function(data){
              window.location.href = baseurl + "collection/get_monthly_dues_report";
          },
          error: function(data){
  
          },
      });
  </code></pre>
  
  <p>Here is My Controller</p>
  
  <pre><code>$data = $this-&gt;input-&gt;post('data');
  $data = json_decode($data);
  foreach($data as $r) {
    $this-&gt;excel-&gt;getActiveSheet()-&gt;fromArray(array(
      $r['duedate'], $r['customername'], $r['lotdesc'], $r['daysdue'],
      $r['amountdue'], $r['amortdue'], $r['surcharge'], $r['vat'], $r['ips'],
      $r['interest'], $r['principal'], $r['payments']), null, 'A' . $row
    );
    $this-&gt;excel-&gt;getActiveSheet()
                -&gt;getStyle('A' . $row . ':L' . $row)
                -&gt;applyFromArray($styleArray2);
    $this-&gt;excel-&gt;getActiveSheet()
                -&gt;getStyle('A' . $row . ':L' . $row)
                -&gt;applyFromArray($styleArray4);
    $row ++;
  }
  </code></pre>