Need advice when XHR object is returned in response

Need advice when XHR object is returned in response

jstuardojstuardo Posts: 104Questions: 41Answers: 0
edited December 2018 in Free community support

Hello,

I developed a site that uses DataTable plugin (all of them load data using Ajax). This site has a user authentication mechanism.

What I need to accomplish is, when the datatable is refreshed (by mean of a sort, filter, etc.) and the session has expired, a custom message should be shown and then redirected to login page.

I have implemented this event handler:

       tblCampos.on('xhr.dt', function (e, settings, json, xhr) {
                            checkUserSession(xhr);
                        });

where tblCampos is the datatable.

That works partially. When the user session has expired, a custom message is shown, but the dataTable also shows an alert telling that DataTable receives an invalid JSON response (actual messge is: "DataTables warning: table id=campos - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"). How can I avoid that error message to be shown?

Regards
Jaime

Answers

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

    Hi @jstuardo ,

    It would probably be easier to either destroy() the table when the session has expired, or remove/hide the elements from the DOM. Would that work?

    Cheers,

    Colin

  • jstuardojstuardo Posts: 104Questions: 41Answers: 0

    Hello, i have finally used: $.fn.dataTable.ext.errMode = 'none'; because always the error is shown after the xhr.dt event, and even, the error is shown if I implement error.dt event.

    So, the easiest way for me was to disable errors at all.

    Regards
    Jaime

This discussion has been closed.