v1.5.6 add parameter in json string for server side script

v1.5.6 add parameter in json string for server side script

pakypaky Posts: 106Questions: 0Answers: 0
edited January 2010 in General
Hi all, how can I add two params to server.side.script ?

example:

[code]
....
$sOutput = '{';
$sOutput .= '"sEcho": '.$_GET['sEcho'].', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
/* here my two custom Outputs */
$sOutput .= '"iMeseRiferimentoPresenze": '.$_GET['X'].', ';
$sOutput .= '"iAnnoRiferimentoPresenze": '.$_GET['Y'].', ';
/* o o o o o o oo o o o o o o o */
$sOutput .= '"aaData": [ ';
[/code]

thanks

Replies

  • allanallan Posts: 61,971Questions: 1Answers: 10,160 Site admin
    Hi paky,

    You can use fnServerData. This example shows posting values to the client-side, but it's easy to see that in the callback function for the Ajax request you can access the returned data, and therefore your parameters.

    Regards,
    Allan

    ps. Moving the topic to a different category - the 'releases' category should only be used for software releases.
  • pakypaky Posts: 106Questions: 0Answers: 0
    Hi Allan ok I've add this lines :

    [code]
    "fnServerData": function ( sSource, aoData, fnCallback )
    {
    /* Add some extra data to the sender */
    aoData.push( { "year": "2010", "month": "01" } );
    $.getJSON( sSource, aoData, function (json)
    {
    /* Do whatever additional processing you want on the callback, then tell DataTables */
    fnCallback(json)
    alert(json->year); <--- error
    } );
    }

    [/code]

    How can read year and month param ?

    thanks
  • allanallan Posts: 61,971Questions: 1Answers: 10,160 Site admin
    HI paky,

    Please have a look at this example http://datatables.net/examples/server_side/custom_vars.html . You'll see that jQuery uses a key/value pair in the code. Also if you want it to come back from the server, obviously the server side will need to send it back.

    Regards,
    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    Hi Allan,

    example is the same, my problem is to read the variables back, if alert(aoData[16]);
    Return [object Object] ....
  • allanallan Posts: 61,971Questions: 1Answers: 10,160 Site admin
    HI paky,

    I suggest you use Firebug (or Webkit's inspector) and try console.dir(json) to see the entire object.

    Allan
  • pakypaky Posts: 106Questions: 0Answers: 0
    edited January 2010
    Hi Allan with console.dir(json) returned the same dataTable params (in aaData var) without my added params !!!

    I add to it:
    [code]
    aoData.push( { "year": "2010", "month": "01" } );
    [/code]

    where are they ? thanks
  • allanallan Posts: 61,971Questions: 1Answers: 10,160 Site admin
    edited January 2010
    Hi paky,

    Have a look at the example code in the link I posted (or the jQuery documentation): you need a name/value pair:

    aoData.push( { "name": "more_data", "value": "my_value" } );.

    So in this case you would need to add year, and month. It's counter intuitive and annoying, but it's just how jQuery works.

    Allan
This discussion has been closed.