0
votes

I have a datatable pulling data from the server.

If all is ok it returns a perfectly valid json response which datatbles renders happily, if something is wrong server side it returns json error object as follows.

{"success":false,"message":"some error message"}

My table is defined as follows:

    Table = $('#usersTable').DataTable({
    "pagingType": "full_numbers",
    "serverSide": true,
    "processing": true,
     "ajax": {
          url:"/user/getUsers/"
             }
      });

How would I intercede to stop datatables doing anything so I could process the error message if response.success is defined and false?

I am using the latest version of jquery datatables

1
write your own ajax handler instead of just passing in the url. See docs for how utilize your own ajax within the options object for the plugin - charlietfl

1 Answers

0
votes
Table.on( 'xhr.dt', function (e, settings, json) {
 if (!typeof json.success !== "undefined"){
 if ( json.success==false){
do something here
}
}
});