CodeIgniter - Post multiple arrays to controller
        Posted  
        
            by 
                Bobe
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Bobe
        
        
        
        Published on 2013-10-29T09:32:54Z
        Indexed on 
            2013/10/29
            9:53 UTC
        
        
        Read the original article
        Hit count: 416
        
I have a dynamically generated form that allows users to enter new data and edit existing data. When the form is submitted, it collates the input values and groups them according to whether they are new or not, the former being denoted by class="new-entry".
So the function generates two arrays: updateData and insertData. Both arrays are of similar formats:
[
    0: {
        'id'    = 1,
        'value' = foo
    },
    1: {
        'id'    = 1,
        'value' = 'bar'
    },
    etc...
]
I am combining them into a new array object to send via ajax to the controller:
var postData = {
    'update_data': updateData,
    'insert_data': insertData
};
Then in the ajax call:
$.post(url, postData, function() { // some code });
However, in the controller, doing print_r($this->input->post()) or print_r($_POST) as a test only returns Array(). Even $this->input->post('update_data') returns nothing.
How can I retrieve these arrays in the controller?
© Stack Overflow or respective owner