Adding error-handler to ajax produces additional request

Adding error-handler to ajax produces additional request

VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

I see something strange in console (http://localhost:3001/errajax)
I just added a stub to ajax object and datatables began to produce an additional json-request like:
GET https://datatbl.herokuapp.com/errajax?_=1448540064717

var table = $('#users').DataTable( {

    ajax: { error:  function( e, settings, techNote, message ) {} } 
});

Is it a bug or one more time my mistake?

Answers

  • VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

    See http://plnkr.co/edit/SQ5JE9?p=preview
    I am increasingly convinced that if the datatable settings have even empty

    ajax: {}
    

    DataTable will try to get data via ajax despite the fact that a url is absent (empty).

    I believe this is not convenient because it eliminates the possibility to set up a common error handler in defaults i.e.

      $.extend( true, $.fn.dataTable.defaults, {
    
        ajax: {
          error:  function( e, settings, techNote, message ) {
    
              if( e.status == 401 || e.status == 403 ) {
    
                 console.log(' No way! ');
    
              } else {
    
                 console.log(message);
    
              }
          }
        }});
    

    To avoid the current behavior I have to write

    ajax: null,
    

    for every datatable with static data source.

This discussion has been closed.