久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將標題添加到 window.location.pathname

Add Header to window.location.pathname(將標題添加到 window.location.pathname)
本文介紹了將標題添加到 window.location.pathname的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在為應用設置身份驗證.在我發出登錄請求后,會發送一個 JSON Web 令牌作為響應.我可以通過 Ajax 將它附加到標題中.問題是在登錄后使用 window.location.pathname 重定向時,因為它不是 Ajax 請求,它沒有附加到標頭的令牌.我該如何解決這個問題?

I am setting up authentication for an app. After I make a post request to login, a JSON Web Token is sent in response. I am able to attach this to the header via Ajax. The problem is when using window.location.pathname to redirect after login, since it is not an Ajax request it does not have the token attached to the header. How do I get around this?

$.ajaxSetup({
  headers: {
    'x-access-token': window.localStorage.jwt
  }
});

var Auth = {
  signup: function () {
    console.log('signuppp');
    var userSignup = {
      username: $('#usernameSignup').val(),
      password: $('#passwordSignup').val()
    };
    console.log(userSignup)
    return $.post('/api/users/register', userSignup, function (resp) {
      console.log('resp: ',resp);
      window.localStorage.setItem('jwt', resp.token);
      
      //does not have x-access-token header
      window.location.pathname = '/';
    })
  },

推薦答案

簡短的回答是:您不能使用 window.location 設置 HTTP 標頭.

Short answer is: you cannot set HTTP headers using window.location.

添加Angular 應用程序中 window.location.href 的 http 標頭

這篇關于將標題添加到 window.location.pathname的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is Math.random() cryptographically secure?(Math.random() 在密碼學上是安全的嗎?)
Secure random numbers in javascript?(在javascript中保護隨機數?)
How to avoid multiple token refresh requests when making simultaneous API requests with an expired token(使用過期令牌發出同時 API 請求時如何避免多個令牌刷新請求)
JWT not decoding quot;JWT malformedquot; - Node Angular(JWT 未解碼“JWT malformed;- 節點角度)
How to invalidate a JWT token with no expiry time(如何使沒有到期時間的 JWT 令牌無效)
Authorization header in img src link(img src 鏈接中的授權標頭)
主站蜘蛛池模板: 三级黄色片免费看 | 亚洲精品黄 | 在线黄网 | 亚洲精品一区二区在线观看 | 日本韩国欧美中文字幕 | 久久久久久久 | 国产成人aⅴ | 国产精品一区二区在线播放 | 成人在线观看免费爱爱 | 亚洲www啪成人一区二区麻豆 | 色伊人网| 91插插插插插 | 成人动态视频 | 天堂网久久 | 91亚色视频 | 久久日韩精品 | 黄色三级av | 久久精品免费看 | 成人做受黄大片 | 午夜视频网| 久久久久久亚洲精品 | 香蕉看片 | 不卡的av网站 | 亚洲天天看 | 亚洲高清毛片一区二区 | 久久久久久久 | 在线观看av网站 | 久久伊人久久 | 久久九九视频 | 国产精品高潮呻吟久久 | 一本在线| 免费毛片在线 | 国产精品成人免费精品自在线观看 | 国产视频一二三 | 91精品久久久久久粉嫩 | 成人深夜| 亚洲黄色在线视频 | av中文网 | 国产精品第五页 | 亚洲天堂偷拍 | 国产福利一区二区三区 |