views:

319

answers:

1

Hello Everyone,

I am trying to get my datatable to take a POST JSON output from my server.

This is my client side code:

<script>
$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "http://localhost/staff/jobs/my_jobs",
        "fnServerData": function ( sSource, aoData, fnCallback ) {
            $.ajax( {
                "dataType": 'json', 
                "type": "POST", 
                "url": sSource, 
                "data": aoData, 
                "success": fnCallback
            } );
        }
    } );
} );
</script>

Now I have copied and pasted the server side code found in the DataTables examples found here.

When I change my sAjaxSource to view this page the table doesn't move beyond 'processing'.

When I view the JSON directly I see this output.

{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","First Ever Job"]] }

Just for fun I went to the POST server-side example and copied some of the JSON they are using for their example and just PHP echoed it straight out of another page.

This is the output of that page.

{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","Internet Explorer 4.0"]] }

Here is where it gets interesting.

The JSON that has been processed by the server fails to work yet the JSON simply echo'd by the same server on a different page does work... yet both are identical in outputs.

I hope someone can shed some light on this because as the tree said to the lumberjack... I'm stumped.

Thanks,

Tim

A: 

Hello

I just found out how to view the POST variables with firebug. This showed an error from the server saying that fnColumnToField function was undefined. I checked the server side script and found it at the bottom. I moved the function to the top.

Suddenly the table was working.

This seems strange because i literally copied and pasted the code from the examples on http://www.datatables.net.

Whats even stranger is that when i viewed the page directly it was also showing correct validated JSON output...

Perhaps it has something to do with me integrating this into codeigniter. Either way it is working now and I am a very happy man.

Thankyou Tim

Tim