CodeIgniter: Pass Javascript Array from View to Controller then store to Database
<p>I'm trying to post a javascript array to a controller function in codeigniter then store it into the database via AJAX. I have no problem when passing single values, and this is the first time i'm passing an array. </p>

<p>Here's the code</p>

<pre><code>//JAVASCRIPT IN THE VIEW (students variable already populated and classCode already has a value)
$.ajax({
    traditional: true,
    type: 'POST',
    url: '&lt;?php echo base_url(); ?&gt;index.php/ams_controller/recordAbsence', 
    data: 'classCode='+classCode+'&amp;students='+students, 
    success: function(resp) { 
        alert("Absences Saved");
    }
});


//CONTROLLER FUNCTION
public function recordAbsence() {
    $temp=getdate(date("U"));
    $date = $temp[month] ." ". $temp[mday] ." ". $temp[year];

    $classCode = $this-&gt;input-&gt;post('classCode');
    $students = $this-&gt;input-&gt;post('students');

    $this-&gt;load-&gt;model('model_users');
    if($this-&gt;model_users-&gt;recordAbsence($classCode, $students, $date)) {
        return true;
    } else{
        return false;
    }    
}

//MODEL FUNCTION
public function recordAbsence($classCode, $students, $date) {
    foreach($students as $row) {
        $data = array(
            'stud_no' =&gt; $row,
            'date_of_absence' =&gt; $date,
            'classCode' =&gt; $classCode
        );

        $query = $this-&gt;db-&gt;insert('absence', $data);
    }
    if($query) {
        return true;
    } else {
        return false;
    }
}
</code></pre>

<p>The data isn't being stored in the absence table. Any help would be appreciated.</p>