I have the following function that adjusts the headers of my requests AJAX:
self.authenticate = function () {
self.token = sessionStorage.getItem(tokenKey);
var headers = {};
if (self.token) {
headers.Authorization = 'Bearer ' + self.token;
$.ajaxSetup({
headers: headers
});
}
}
But this does not work, when I check the headers in the developer tables (F12) or in Fiddler, I do not see the custon header, but when I set the header to the request, and not through ajaxSetupit it works fine.
On the Layout page, the authenticatefollowing functions are called :
$(document).ready(function () {
var avm = new AuthenticationViewModel();
avm.authenticate();
});
And self.tokennot null.
For example, for this request:
self.getUsers = function (callback) {
$.get("../API/Users/GetUsers/",callback);
}
these are the headers:

What am I missing?
source
share