How to catch if response status code is 404 in server side data tables?

How to catch if response status code is 404 in server side data tables?

madusankamadusanka Posts: 20Questions: 7Answers: 0
edited November 2019 in Free community support

here is what i done so far

$('#field_list').DataTable().destroy();
                self.dataTable = $("#field_list").DataTable({
                    processing: true,
                    serverSide: true,
                    searching: false,
                    "aaSorting": [ [0,"desc" ]],
                    "scrollX": true,
                    ajax: {
                        data: function (data) {
                            data.token = localStorage.getItem("token"),
                        },
                        'url': '/api/v1/site-field-library,

                        dataFilter: function (data) {
                            self.closeFullPageLoader();
                            var json = jQuery.parseJSON(data);
                            var response = json.data.searchResults;
                            self.fields = response.site_fields;
                            json.data = response.site_fields;
                            json.recordsFiltered = response.recordsFiltered;
                            json.recordsTotal = response.recordsTotal;
                            return JSON.stringify(json);
                        }
                    },
                    columns: [.......]
 });

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    This thread should help,

    Colin

  • madusankamadusanka Posts: 20Questions: 7Answers: 0

    @colin actually what i want is to know how should i catch response exceptions like 404 when using server side datatables. can you please give me a solution?

    thanks

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    This SO thread discusses what to do in that scenario.

    Colin

  • madusankamadusanka Posts: 20Questions: 7Answers: 0

    i got the solution

    'error': function(error) {
                                if (error && error.status == 404) {
                                    self.notFound = true;
                                }
                            },
    
  • madusankamadusanka Posts: 20Questions: 7Answers: 0

    thank you so much @colin.

This discussion has been closed.