Show Custom error message for 'Warning: Ajax error'
Show Custom error message for 'Warning: Ajax error'
ruwantharatnayake
Posts: 1Questions: 1Answers: 0
DataTables warning: table id={id} - Ajax error will typically occur when the server responds with anything other than a 2xx HTTP status code.
Is it possible to show a custom error message than the generic one?
And is it possible to show status code specific error for some status codes and leave default behavior as it is?
Answers
You can listen for the
xhr
event, which gives access to the JSON return and the XHR object, so you can check status codes etc. You can then show the error message as you wish.However, the DataTables error will still be shown. You can use
DataTable.ext.errMode
to tell DataTables to either not show an error or to do something else with it (including making it a function to show your own message, as an alternative to using thexhr
event).Allan