How to pass an array from javascript to controller using codeigniter
Here is my code:
view:
function submitFunc(){
var arrayName = ['John ' , 'Josh' , 'Steph'];
var arraySerial = [ 123, 456 , 789];
$.ajax({
type: 'post',
data: {arrayName:arrayName, arraySerial: arraySerial }, //not sure of this code
url: '<?= base_url()."mycontroller/insertData"?>',
success: function(data){
}
});
}
and in my controller:
public function insertData()
{
$data = array(
'Name' =>$this->input->post('arrayName'),
'Serial' =>$this->input->post('arraySerial '),
);
$this->db->insert('test',$data);
}
trying to achieve something like this n database:
| Name | Serial| | John | 1 | | Josh | 2 | | Steph | 3 |