DataTables Ajax Error, can I catch this and redirect?
DataTables Ajax Error, can I catch this and redirect?
I have an application that users have to sign into with authentication to use and it uses DataTables on one of the pages. I use an ajax source and ever 5 minutes I'm triggering a
datatable.ajax.reload(null, false);
The problem I'm having is that if a user signs out (maybe they had multiple tabs open?) then when the above command is triggered, I get a pop up saying ajax error with datatables (because they're signed out and I'm providing a 401/403 response instead of JSON).
How can I instead of having an ajax error pop up show, redirect the user to the sign in page when a 401/403 response is returned?
This question has an accepted answers - jump to answer
Answers
I see there is an xhr and prexhr event. Can I do something with these?
The
$.fn.dataTable.ext.errMode
option can be used for this. See the documentation in theerror
event.Allan