Add custom headers to Ajax when loading data
Add custom headers to Ajax when loading data
Hello,
I need to add custom headers to Ajax requests when loading data for DataTables, but I don't know if it is possible directly from DataTables.
It is possible to add data to the Ajax petition, but I don't see any option to add custom headers. This is how we included the data:
'ajax': {
'url': url,
'type': 'GET',
'data': function ( data ) {
data.token = token;
}
}
How can we add custom headers to the Ajax call in DataTables?
Using jQuery, it would be:
$.ajax({
type: 'GET',
url: url,
data: '',
beforeSend: function (request) {
request.setRequestHeader("token", token);
}
});
Thanks!
Replies
Ah, nice!
You can add 'beforeSend' the same way in DataTables!!! :)
Allan, could you add this to docs?