Uncaught TypeError: Cannot read property 'length' of undefined

Uncaught TypeError: Cannot read property 'length' of undefined

pwigginspwiggins Posts: 4Questions: 3Answers: 0

I've seen several examples of this problem but still haven't been able to find a resolution.

The error says it breaks on jquery.dataTables.js on line 3287 shown below

// Got the data - add it to the table
                    for ( i=0 ; i<aData.length ; i++ ) {
                        _fnAddData( settings, aData[i] );
                    }

This is my controller. The controller is this way because the the lack of db connection right now, but will have JSON returned in the same format as $data. I have tried several things to resolve the error, but keep running into other issues.

public function test()
    {
   $data = '{"persons": [{"branch": "CORP","phone_numbers": [{"desk": "5223422117"},{"mobile": "5022319224"},{"branch": "422-922-2291"}],"email": "twilliams@test.com","preferred_name": "Thomas","person_id": 368,"department": "IT","first_name": "Thomas","title": "Programming Manager","last_name": "Williams"}]}';

        $data = json_encode($data);
        print $data;

    }

My javascript

  $(document).ready(function() {
           $('#directory_table').dataTable( {
               "ajax": {
                   "url": "test",
                   "type": "JSON"
               },
               "aoColumns": [
                   { "persons": "preferred_name" },
                   { "persons": "last_name" },
                   { "persons": "phone_numbers.0" },
                   { "persons": "phone_numbers.1" },
                   { "persons": "phone_numbers.2" },
                   { "persons": "email" },
                   { "persons": "department" },
                   { "persons": "title" }
               ]
           } );
       } );

My HTML

<table id='directory_table' class="display">
        <thead>
            <tr style='background: #186A9F; color: white;'>
                <th>First Name </th> 
                <th>Last Name</th>
                <th>Desk Number</th>
                <th>Mobile</th>
                <th>Branch</th>
                <th>Email</th>
                <th>Department</th>
                <th>Title</th>
            </tr>
        <thead>
    </table>
This discussion has been closed.