'preXhr.dt' not fired on first ajax request (after page load)

'preXhr.dt' not fired on first ajax request (after page load)

kmd1970kmd1970 Posts: 36Questions: 8Answers: 1
edited March 2016 in DataTables 1.10

I am not seeing any console output with the first ajax request (after page load).

The preXhr.dt event doesn't seem to fire until i sort or search.

...on('preXhr.dt', function ( e, settings, data ) {
        console.log('preXhr',data);
 });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Have you attached it before the DataTable is initialised? Otherwise the event listener will be added after the first Ajax request has been sent.

    Allan

  • kmd1970kmd1970 Posts: 36Questions: 8Answers: 1

    Sorry, I didn't think location mattered.

    so

    $('#example').on('preXhr.dt', function ( e, settings, data ) {
            console.log('preXhr',data);
     }).DataTable();
    

    Not

    $('#example').DataTable().on('preXhr.dt', function ( e, settings, data ) {
            console.log('preXhr',data);
     });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Looks good. DataTables does a number of things when you call it, including sending off the Ajax request if you configure it with ajax. The draw event is another one to watch out for like this.

    Allan

This discussion has been closed.