server side processing and ajax source

server side processing and ajax source

vaizemanvaizeman Posts: 4Questions: 0Answers: 0
edited January 2010 in General
Hi,
I use datatables 1.6 and jquery 1.4.

this is my script:

[code]
$(document).ready(function() {
$('#list').dataTable({
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": "ajax/index.php",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "myVar", "value": "2" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
}
});
});
[/code]

I have these problems:

1) if I set "bServerSide": true the table doesn't display anything. So I set "bServerSide": false and it works.
2) I'm trying to pass additional parameter to the ajax/index.php but the $_GET['myVar'] on the php page always returns null.

thanks i advance for your help.

Leo

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    1. If you are using server-side processing, are you sure it's returning all the required parameters in the required format: http://datatables.net/usage/server-side ? www.jsonlint.com is useful for validating json data.

    2. I don't see anything wrong with your variable. If you do a print_r($_GET); does it show up then? (you'll need to use Firebug, etc, to view the XHR return).

    Allan
  • vaizemanvaizeman Posts: 4Questions: 0Answers: 0
    Hi Allan,
    thank you for your answer

    about the first point this is the output validated with jsonlint:

    {
    "sEcho": 0,
    "iTotalRecords": 2,
    "iTotalDisplayRecords": 2,
    "aaData": [
    [
    "1",
    "Pippo",
    "Pipponi",
    "Pippo srl",
    "p",
    "p",
    "213_209_210_50",
    "1",
    "2010-01-14 17:20:55"
    ],
    [
    "2",
    "Toto",
    "Riina",
    "Cosa Nostra SPA",
    "t",
    "t",
    "213_209_210_50",
    "1",
    "2010-01-14 17:22:03"
    ]
    ]
    }

    now if I set "bServerSide": false, the table displays the data otherwise not.

    what's wrong with this?

    Leo
  • vaizemanvaizeman Posts: 4Questions: 0Answers: 0
    Hi,
    I resolved the problem, it was my fault.
    thank to your advise to use firebug, it helps me showing a php warning inside the output source.

    Leo
This discussion has been closed.