PHP data ( server_processing.php ) stop returning data if variable is not hardcoded in script

PHP data ( server_processing.php ) stop returning data if variable is not hardcoded in script

kinologikkinologik Posts: 1Questions: 0Answers: 0
edited March 2012 in General
I've been chasing my tail for the last 48 hours with this problem :(

I'm trying to pass a variable to server_processing.php so I could show filter data depending on who is logged to the webpage.

I found this and was excited to try the script : http://www.datatables.net/forums/discussion/5360/where-condition-does-anyone-find-the-solution/p1

Well looks like it doesn't work for me... I tried all other kind of workaround (session variable, post, get, javascript variable... nada, nothing, rien).

Through my trials & error process, I was able to isolate the following behavior:

At the very beginning of the server_processing.php script, if I hardcode a username like this...

[code]
$tempUsername = "didomi";
[/code]

... everything works as expected. But if I try to assign the variable differently...

[code]
$tempUsername = $_SESSION['username'];
[/code]

... it stops working. No data, nothing. I "echo"ed $_SESSION['username'] and the value is right... but the table stays empty.

Even weirder, if I try to use a custom object (which would be my preferred method)...

[code]
$tempUsername = $rrUser->getUSERNAME();
[/code]

... not only do I get nothing, I also get the following message:

[quote]DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.[/quote]

Again, the value returned by $rrUser->getUSERNAME() is identical to $_SESSION['username'], both returning "didomi".

Any ideas?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    What is the error message that is returned from the server in the JSON message that is causing the error?

    Have you called session_start() to start the session at the top of the server processing file?

    Allan
  • kinologikkinologik Posts: 1Questions: 0Answers: 0
    If this can be helpful...

    [code]
    var anOpen = [];

    var sImageUrl = "/img/interface/js/dataTables/";
    var sImgActUrl = "/img/interface/table/";

    var rDATA = {}; var tDATA; var rID;

    $(document).ready(function() {

    oTable = $('#riskHistory').dataTable({
    "aoColumnDefs": [
    {
    "fnRender": function (o,v) {
    rID = o.aData[0]; tDATA = rDATA[rID] = {};

    rDATA[rID]['Manager'] = o.aData[1];
    rDATA[rID]['Platform'] = o.aData[2];
    rDATA[rID]['Trader'] = o.aData[3];
    rDATA[rID]['Category'] = o.aData[4];
    rDATA[rID]['Type'] = o.aData[5];
    rDATA[rID]['Status'] = o.aData[8];
    rDATA[rID]['Date'] = o.aData[9];
    rDATA[rID]['Action'] = o.aData[11];
    rDATA[rID]['Closed'] = o.aData[12];

    var requestForm = ''; requestForm +=
    ''+
    ''+
    ''+
    ''+
    ''+
    ''+
    '';

    return requestForm + '';
    },
    "sClass": "control center btnCTRL",
    "sWidth": "24px",
    "bSortable": false,
    "aTargets": [ 0 ]
    },
    {
    "bVisible": false,
    "aTargets": [ 1 ]
    },
    {
    "sClass": "dtCenter",
    "sWidth": "60px",
    "aTargets": [ 2 ]
    },
    {
    "sWidth": "80px",
    "aTargets": [ 3 ]
    },
    {
    "bVisible": false,
    "aTargets": [ 4 ]
    },
    {
    "bVisible": false,
    "aTargets": [ 5 ]
    },
    {
    "fnRender": function(){return requestMessage(tDATA);},
    "sWidth": "280px",
    "aTargets": [ 6 ]
    },
    {
    "fnRender": function(){return requestAction(rID,tDATA);},
    "sWidth": "40px",
    "bSortable": false,
    "aTargets": [ 7 ]
    },
    {
    "sClass": "dtCenter",
    "sWidth": "60px",
    "aTargets": [ 8 ]
    },
    {
    "fnRender": function (o,v) {
    tDate = o.aData[9].replace(" ", "
    ");
    tDate = tDate.replace("201", "1");
    return tDate + "";
    },
    "sWidth": "60px",
    "sClass": "dtCenter",
    "aTargets": [ 9 ]
    },
    {
    "fnRender": function (o,v) {
    tCls = parseInt(o.aData[12]);
    if (!(tCls)) {return 'Cancel'} else {return ''};
    },
    "sClass": "dtCenter btnCTRL",
    "sWidth": "1px",
    "bSortable": false,
    "aTargets": [ 10 ]
    },
    {
    "bVisible": false,
    "aTargets": [ 11 ]
    },
    {
    "bVisible": false,
    "aTargets": [ 12 ]
    }
    ],
    "aaSorting": [[ 9, "desc" ]],
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bServerSide": true,
    "sAjaxSource": "/db/trader/server_processing.php"
    });
    } );
    [/code]
This discussion has been closed.