How to add Authorization header to AJAX requests

How to add Authorization header to AJAX requests

conrad10781conrad10781 Posts: 2Questions: 0Answers: 0
edited August 2013 in General
Our API endpoint makes use of HTTP authentication. Currently, with jQuery we do the following:

[code]
$.ajax({
....
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', apiAuthorization);
},
....
});
[/code]

Is there anyway to apply this logic to the DataTables utility?

Replies

  • conrad10781conrad10781 Posts: 2Questions: 0Answers: 0
    I found the solution. Using "fnServerData" ( http://datatables.net/usage/callbacks#fnServerData ) I was able to add the beforeSend.
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Perfect - fnServerData is the way to go. In v1.10 there will be an `ajax` option which will be easier to use.

    Allan
This discussion has been closed.