Problems with POST Server Side JSON output

Problems with POST Server Side JSON output

tdmohrtdmohr Posts: 16Questions: 2Answers: 0
edited June 2010 in General
Hello Everyone,

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

This is my client side code

[code]
$(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
} );
}
} );
} );
[/code]

I then also have the server-side code from the 'server-side' examples page which outputs the following JSON

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

That wasn't working for me so I grabbed the JSON output of the POST server side example and simply echoed that on another page

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

So basically the JSON that has been processed by the server fails to work and the JSON simply outputted 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

Replies

  • codingavenuecodingavenue Posts: 22Questions: 0Answers: 0
    Hi,

    When you said it's not working, what exactly happen? Was there an error?
    What does firebug says during the ajax call?

    codingavenue
  • tdmohrtdmohr Posts: 16Questions: 2Answers: 0
    hello

    When I say nothing happens i mean the processing div stays up and no data makes it into the table.

    Firebug shows that my table makes a single POST call to the JSON page. because its using post i cant view the variables though right?

    When I point the sAjaxSource to the echo'd output, the same call is made but to the new URL and everything works great.

    Does this help?

    Thanks

    Tim
  • tdmohrtdmohr Posts: 16Questions: 2Answers: 0
    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 copy and pasted the code from the examples. When i viewed the page directly it was also showing correct validated 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
  • joetraffjoetraff Posts: 2Questions: 0Answers: 0
    edited July 2010
    Good to hear that.
    Keep up the good work.


    http://www.eurodebt.com/
This discussion has been closed.