v1.5.6 add parameter in json string for server side script
v1.5.6 add parameter in json string for server side script
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
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
This discussion has been closed.
Replies
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.
[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
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
example is the same, my problem is to read the variables back, if alert(aoData[16]);
Return [object Object] ....
I suggest you use Firebug (or Webkit's inspector) and try console.dir(json) to see the entire object.
Allan
I add to it:
[code]
aoData.push( { "year": "2010", "month": "01" } );
[/code]
where are they ? thanks
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