How to catch ajax connection error and stop Datatables from throwing an alert?

How to catch ajax connection error and stop Datatables from throwing an alert?

edwardcedwardc Posts: 30Questions: 11Answers: 0

I use connection to multiple sites that are source for my data. One's may be offline at some point and I just want to catch the error (ajax could not load) and inform the user and move on.
This should be pretty simpler but I can't figure it out.

  • I managed to catch the error using documentation from here: event: error
  • I [... do something with the error...]
  • but then I get: "DataTables warning: table id= myID - Ajax error. For more information about this error, please see http://datatables.net/tn/7"

How can I ask Datatable to do nothing after processing my error function?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,458Questions: 1Answers: 10,057 Site admin

    Have your error handler return true. That should be all that is needed (although I've got a feeling you are going to tell me not... If so, can you give me a link to the page?).

    Allan

  • edwardcedwardc Posts: 30Questions: 11Answers: 0

    Woow... you must have some paranormal skills. :-)

    I pm you with the link to the page and the JS.
    Here is the code to initialize dt:

    jQuery(document).ready(function () {
        AppCalendar.init();
        $("#tournament_schedule_table").DataTable({
            "ajax": "include/table_ajax.php",
            columns: [
                {title: "Week"},
                // {... something, something, something }
            ],
    
            // read the custom filters from saved state and populate the filter inputs
            "lengthMenu": [
                [10, 20, 50, 100, 150, -1],
                [10, 20, 50, 100, 150, "All"] // change per page values here
            ],
            "pageLength": 10, // default record count per page
    
            "order": [
                [1, "asc"]
            ]// set first column as a default sort by asc,
        })
            .on( 'error.dt', function ( e, settings, techNote, message ) {
            console.log( 'Error: Calendar DataTables: ' + message ); // for test purpose
            return true;
        } );
    });
    
  • edwardcedwardc Posts: 30Questions: 11Answers: 0

    any news?

  • allanallan Posts: 61,458Questions: 1Answers: 10,057 Site admin
    Answer ✓

    Sorry - I hadn't fully understood that the issue was still present with the above code.

    Could you give me a link to an error showing the issue so I can trace it through please?

    Allan

  • edwardcedwardc Posts: 30Questions: 11Answers: 0

    sent as pm

This discussion has been closed.