1

Im using Datatables and server side processing for data loading.

For the current implementation the table data generates without any error unless there is an session expiry or server timeout.

I would like to handle server side exceptions and if everything is ok, the table data should load.

The below is the function

let scheduler_name  =   $("#sche_name").val().trim();

$('#monitor_scheduler_tbl').DataTable( { 
    "aoColumnDefs": [
    { 'bSortable': true, 'aTargets': [0,1,2,3] },{ "bSearchable": false,'aTargets': [-1] }], 
    "processing": true,
    "bDestroy": true,
    "bFilter":false,
    "serverSide": true,
    "ajax": {
        "url": config.yaws_file_path + "css_monitor_scheduler.yaws",
         "data": function ( d ) {
            d.action            = "SEARCH_SCHEDULER",
            d.scheduler_name    = scheduler_name;
        },
        "complete": function(response){

            res = JSON.parse(response.responseText);

            if(error = res['err'])
            {
                objApp.showToastMessage('error', error);
            }
        }
    }
});
Sherantha Perera
  • 47
  • 1
  • 2
  • 11
  • this looks related https://stackoverflow.com/questions/7658975/handling-session-time-outs-in-datatables-with-server-side-datasource-processing?rq=1 – ryan2johnson9 Jan 17 '18 at 05:43

1 Answers1

1

On the server side, you should respond with HTTP error codes to different situations.

On the client side, you can define an ajax error handler to dataTables that recognizes these response codes:

"ajax": {
  "error" = function (jqXHR, textStatus, error) {
    if (jqXHR && jqXHR.status == 440) {
      // Session expired - do something here
    } else if (jqXHR && jqXHR.status == 408) {
      // Request timeout - do something here
    } else {
      // Some other error - do something here
    }
  }
lofihelsinki
  • 2,491
  • 2
  • 23
  • 35