Hello everybody,

I have been struggling with this for days and I'd like some help. 
I'm working with DataTables plugin and I'm trying to load data related to 
University's careers from a database and populate the table through Ajax. 
The issue is that I don't much about Ajax and JSON and I got this error 
message:

*DataTables warning: table id=tableCareers - Invalid JSON response. For 
more information about this error, please see http://datatables.net/tn/1*

I checked the JSON on an online JSON Validator and the result is positive 
so the problem might be on the Ajax part.

This is my code so far.

Model
db.define_table('Degree',
                Field('description','string'),
                format = '%(description)s'
               )


db.define_table('Faculty',
                Field('description','string'),
                format = '%(description)s'
               )


db.define_table('Career',
                Field('name','string'),
                Field('duration (Years)', 'integer'),
                Field('faculty','reference Faculty', requires = IS_IN_DB(db,
db.Faculty.id,'%(description)s'),
                Field('degree','reference Degree', requires = IS_IN_DB(db,db
.Degree.id,'%(description)s')
                format= ' %(name)s '
               )

Controller (Tool/manageCareer.py)

def manageCareer():
    import json
    rows = db((db.Career.faculty == db.Faculty.id)&(db.Career.degree == 
db.Degree.id)).select()
    return dict(results=XML(rows.as_json())) 

View

<script>
var table;
$(document).ready(function(){
   table=$('#tableCareers').DataTable( {
        'processing': true,
        'serverSide': true,
        'ajax': 
         {
             type:'POST',
             url:"{{=URL('Tool', 'manageCareer')}}",
             data:{{=results}},
         },
        'columns': [
            { data: 'Career.name'},
            { data: 'Career.duration' },
            { data: 'Faculty.description' },
            { data: 'Degree.description' },
        ],
       
    });

     });
</script>


<table id="tableCareers" >
   <thead>
       <tr>
          <th>Name</th>
          <th>Duration (Years)</th>
          <th>Faculty</th>
          <th>Degree</th>
       </tr>
    </thead>
    <tbody></tbody>
</table>



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/89150a7e-25ed-4f75-a275-2eca219f597d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to