Datatable - Requested Unknown Parameter after User Inactivity

Datatable - Requested Unknown Parameter after User Inactivity

roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0
edited March 2021 in Free community support

I am developing a simple role based PHP application in which Data Table is implemented. The scenario goes as The user will be signing in to the system using session and cookies. his role would be identified with the same session and cookies which matches user credentials and fetch table records as per the role. The problem I am facing is after sometime of inactivity whenever a POST request is made, I am having an error - datatables warning table id= - requested unknown parameter '0' for row 0 column 0 tn/4

Its working fine in local. I thought increasing sessions timeout might help, but unfortunately NO. its getting logged out after 30 mins although every session is set manually in codes, php.ini and CPanel's PHP Selector. I will share the code block below.

var table = $('#example').DataTable( {
    "processing":   true,
    "serverSide":   true,
    "order": [[ 1, "asc" ]],
    "paging"    :   true,
    "searching" :   true,
    "sDom": 'Brtip',
    "defaultContent": "-",
    "targets": "_all",
    "iDisplayLength"    :   100,
    "ajax": {
        url  :"fetchdatarecord.php",
        type : "POST",
    },
    "autoWidth": false,
    "aoColumnDefs": [{ "bSortable": false, "bSearchable": false, "aTargets": [1,2,3,4 ]},],
    "aoColumns": [{ "sWidth": "5%" }, { "sWidth": "5%" },{ "sWidth": "2%" }, { "sWidth": "3%" },{ "sWidth": "2%" }]
} );

Finally on fetchdatarecord I am getting the data as this with columns and set with JSON

if($role == "admin"){
    $subdata[]=$row[0];
    $subdata[]=$row[1];
    $subdata[]=$row[2];
    $subdata[]=$row[3];
    $subdata[]=$row[4];
}

Then Finally -

        $json_data=array(
            "draw"              =>  intval($request['draw']),
            "recordsTotal"      =>  intval($totalData),
            "recordsFiltered"   =>  intval($totalFilter),
            "data"              =>  $data
        );
        echo json_encode($json_data);

All fetching records are working fine. except, as mention due to the user inactivity, the error throws up and the tables are going empty. if I reload the page it takes me to login page. Can share the PHP part if necessary.

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited March 2021

    The place to start is with the troubleshooting steps in the technote link:
    https://datatables.net/manual/tech-notes/4

    When the failure occurs what is in the JSON response? I suspect its not table data but something else due to the session timeout.

    Kevin

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    Please check the image to see the JSON response. https://pasteboard.co/JV0TgdF.png

    The JSON response is having no issues. I am getting all data from the server I believe. after clicking ok of the error alert, it returned the JSON object and the table is empty. if i reload, it takes me to login page, and if I login again I am able to see everything. Yea, as you said it should be a session issue.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Is that the JSON response that generated the alert? That is the response to look at.

    Kevin

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    Whenever I make a POST request on the application which is in the datatable, this happens. this generates the alert. The JSON response I received from the server is in the console which I shared the screenshot there.

    Regards

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    For some reason I'm not able to see the link you posted. IIRC the data object is an array of arrays. I don't remember seeing if one of the arrays was open to see what it contains. Does it contain an array of data for the row or is it empty when the error occurs?

    The best option would be to provide a link to your page so we can take a look. Otherwise maybe you can use the debugger, when the error occurs, and post the resulting ID for the developers to take a look.

    Kevin

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    okay Kevin,

    Thanks for the quick responses. As per the debugger I am having two issues. but styles. :neutral: How styling issue can throw that alert. I am confused.

    The errors are -

    1. The CSS for this table has border-collapse: collapse which is not supported by DataTables, particularly when scrolling is enabled. A collapsed border makes the column width calculations virtually impossible for alignment between columns. Please use border-collapse: separate and suitable border CSS statements to achieve the same effect.

    2. This table has max-width applied to its CSS which can cause issues, particularly in Safari. Setting max-width will not allow the table to expand beyond the value given, meaning that column alignment and scrolling can be effected.

    Am I on the right track? Please guide

    Regards,
    Zaid

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    I'm not sure what those errors are but they won't have an effect on the JSON response. The debugger trace will contain the JSON response for the developers to look at. Make sure to run it once you get the error.

    Kevin

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    Check out the response Kevin.

    Data source: Ajax
    Processing mode: Server-side
    Draws: 1
    Columns: 13
    Rows - total: 82
    Rows - after search: 82
    Display start: 0
    Display length: 100

    Regards,
    Zaid

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    When the error occurs follow the upload steps documented in the privacy section and post the resulting upload ID here for the developers.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Are you able to link to your page or create a test case so we can take a look? Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    Hi,

    oruvuq - this is the debug code from the debugger. if thats correct :neutral:

    Regards,
    Zaid

  • roshan_zaidroshan_zaid Posts: 7Questions: 1Answers: 0

    it is definitely PHP Timeout issue. but my question is vene if its timed out, why the data table throws that error. it can simple be logged out :/ because even the JSON response is received. :/

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Thanks for the debug trace - it shows that the response from the server contains:

    {
        "draw": 1,
        "recordsTotal": 4792,
        "recordsFiltered": 4792,
        "data": [
            [],
            [],
            [],
            [],
            [],
    

    The data array's inner arrays are all empty for all eight tables. I'd say you actually want to just return data: [] in this case (rather than having inner arrays).

    Also, you should include something like "sessionTimeout": true in your JSON and then use the xhr event to look for that parameter, and if present do a window.location.reload() to go back to the login page.

    Allan

This discussion has been closed.