Initially, I aim to construct a basic array with information from the input
Then, I intend to iterate through and create an array using the rows from the table.
Insert your code here.
var first_array = {
"warehouse": $("#warehouse").val(),
"pricelist": $("#pricelist").val(),
"date": $("#date").val(),
"docstatus": "DR",
"paymentterm": $("#paymentterm").val()
}
var second_array = []; //Credit to sagar1025 for assisting in creating the second array
$("#table_main tbody > tr").each(function() {
var cells = $(this).find('td');
second_array.push({
"line": $(cells[0]).html(),
"code": $(cells[1]).html()
});
});
/*Here is my ajax*/
$.ajax({
data: {
array1: first_array,
array2: second_array
},
url: "<?php echo base_url() ?>main/save_data",
type: 'POST',
async: false,
cache: false,
success: function(response) {
},
error: function() {
toastr.error('ERROR', '', {
progressBar: true,
closeButton: true
});
}
});
Next, I need to iterate through the second array in my php
file.
Below is how I declare one variable from the first_array
$docstatus = trim($this->input->post('array1[docstatus]', TRUE));
$array = $this->input->post('array2[]', TRUE);
I am utilizing codeigniter