javascript - Navigate to URL with additional header - Stack Overflow

Is there anyway we can navigate (via <a> click) to a URL with additional header in the request ?

Is there anyway we can navigate (via <a/> click) to a URL with additional header in the request ? here's my code :

i have an <a href="#" id="aUsers"/> tag, and then i handle the onClick() event via JQuery :

$('#aUsers').click(function () {
  var spAuthData = sessionStorage.getItem('sp-auth-data');
  window.location.href = '/users.html?sp-auth-data' = spAuthData;
});

I want to put the spAuthData value in the authorization header, so i can have a clean URL

Is there anyway we can navigate (via <a/> click) to a URL with additional header in the request ? here's my code :

i have an <a href="#" id="aUsers"/> tag, and then i handle the onClick() event via JQuery :

$('#aUsers').click(function () {
  var spAuthData = sessionStorage.getItem('sp-auth-data');
  window.location.href = '/users.html?sp-auth-data' = spAuthData;
});

I want to put the spAuthData value in the authorization header, so i can have a clean URL

Share Improve this question asked Sep 7, 2015 at 4:05 sad301sad301 3961 gold badge3 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

As far as I know, there is no way to manipulate HTTP headers with a plain url.

You can use headers parameter of jQuery AJAX request if it is suitable in your situation. For example, you can update the contents of some divs with AJAX HTML response.

$.ajax({
    url: '/users.html',
    headers: { 'Authorization': spAuthData }
}).done(function() 
{
});

Otherwise, it looks like you need to make some server-side changes.

But why don't you use cookies or something like this?
Authorization is used only by unauthorized users during authorization. In my opinion, sending this header on every request from the browser manually sounds bad. The best approach is to send this header once during authorization, create a user session and store it in cookies (as an access-token, forms ticket or whatever else).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745672504a4639490.html

相关推荐

  • javascript - Navigate to URL with additional header - Stack Overflow

    Is there anyway we can navigate (via <a> click) to a URL with additional header in the request ?

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信