jQuery DataTables: Problems with POST Server Side JSON output

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-06-10T01:07:06Z Indexed on 2010/06/10 1:12 UTC
Read the original article Hit count: 742

Filed under:
|
|
|
|

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 almost 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

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery