0

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

2
  • Take a look here -datatables.net/forums/discussion/7325/… Commented Jan 9, 2015 at 7:20
  • 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 Commented Jan 9, 2015 at 7:46

1 Answer 1

0
Table.on( 'xhr.dt', function (e, settings, json) {
 if (!typeof json.success !== "undefined"){
 if ( json.success==false){
do something here
}
}
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.