Show Custom error message for 'Warning: Ajax error'

Show Custom error message for 'Warning: Ajax error'

ruwantharatnayakeruwantharatnayake 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

  • allanallan Posts: 61,805Questions: 1Answers: 10,119 Site admin

    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 the xhr event).

    Allan

Sign In or Register to comment.