Cannot catch session expire

Cannot catch session expire

lunguc@hotmail.comlunguc@hotmail.com Posts: 20Questions: 6Answers: 0
edited August 2020 in Free community support

Hi all,
I'm using a server side processing and I want to treat session expire behavior but I'm not able to do this.
I receive this error:

jquery.dataTables.min.js:40 Uncaught TypeError: Cannot read property 'length' of undefined
at wb (jquery.dataTables.min.js:40)
at jquery.dataTables.min.js:37
at i (jquery.dataTables.min.js:35)
at Object.success (jquery.dataTables.min.js:36)
at l (app.js?v=1.0:1)
at Object.fireWith [as resolveWith] (app.js?v=1.0:1)
at E (app.js?v=1.0:1)
at XMLHttpRequest.<anonymous> (app.js?v=1.0:1)

I've tried this without success:
$.fn.dataTable.ext.errMode = function ( settings, helpPage, message ) { console.log(message); }
The above function is never triggered.

Also the error function is never triggered and it does not write in console:
$('#table').DataTable({ ajax: { dataType: "JSON", type: "POST", url: url, data: [], async: true, error: function (xhr, error, code) { console.log(xhr); console.log(code); } }

The global configuration for ajax works for all cases except datatables:
$.ajaxSetup({ statusCode: { 401: function(){ location.href = "/"; }, 419: function(){ location.href = "/"; } } });

I'm using https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js

Any idea?

Replies

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Send back a JSON structure such as:

    {
      "error": "Session expired",
      "data": []
    }
    

    which should do it.

    Allan

  • lunguc@hotmail.comlunguc@hotmail.com Posts: 20Questions: 6Answers: 0

    Thanks Allan,
    It works fine but now I have an automatic alert with the message "Session expired". How should I do to avoid to show it?

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Don't return the error parameter if you don't want it to show an error message.

    Allan

This discussion has been closed.