1

I need to include some data to to ajax request before request send. I set up event handler preXhr.dt but it doesn't fire by some reason

$('.js-paging').on('preXhr.dt', function(e, settings, data){
    console.log(settings, data)
})

So no log data, event haven't fired.

HTML

<span class="previous paginate_button">
    <a class="link js-paging" href="#">Previous</a>
</span>
7
  • You should attach this event to datatable element. Commented Jul 17, 2015 at 12:17
  • @py3r3str ok, did $('.transactions_table').dataTable().on('preXhr',... not work either Commented Jul 17, 2015 at 12:26
  • Shouldn't be event attached before creating datatable? Commented Jul 17, 2015 at 12:34
  • @py3r3str can you please bring an example Commented Jul 17, 2015 at 12:41
  • example is there: datatables.net/reference/event/preXhr Commented Jul 17, 2015 at 12:50

1 Answer 1

2

All events in dataTables is triggered directly on the <table> element itself (look for _fnCallbackFire in the source => $(settings.nTable).trigger( e, args )), thus you cannot catch the event on an arbitrary <a> element as you do above.

$('table').on('preXhr.dt', function(e, settings, data){
$('#<table-id>').on('preXhr.dt', function(e, settings, data){
$('.<table-class>').on('preXhr.dt', function(e, settings, data){

works.

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.