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

將標(biāo)題添加到 window.location.pathname

Add Header to window.location.pathname(將標(biāo)題添加到 window.location.pathname)
本文介紹了將標(biāo)題添加到 window.location.pathname的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在為應(yīng)用設(shè)置身份驗(yàn)證.在我發(fā)出登錄請(qǐng)求后,會(huì)發(fā)送一個(gè) JSON Web 令牌作為響應(yīng).我可以通過(guò) Ajax 將它附加到標(biāo)題中.問(wèn)題是在登錄后使用 window.location.pathname 重定向時(shí),因?yàn)樗皇?Ajax 請(qǐng)求,它沒(méi)有附加到標(biāo)頭的令牌.我該如何解決這個(gè)問(wèn)題?

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 = '/';
    })
  },

推薦答案

簡(jiǎn)短的回答是:您不能使用 window.location 設(shè)置 HTTP 標(biāo)頭.

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

添加Angular 應(yīng)用程序中 window.location.href 的 http 標(biāo)頭

這篇關(guān)于將標(biāo)題添加到 window.location.pathname的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Is Math.random() cryptographically secure?(Math.random() 在密碼學(xué)上是安全的嗎?)
Secure random numbers in javascript?(在javascript中保護(hù)隨機(jī)數(shù)?)
How to avoid multiple token refresh requests when making simultaneous API requests with an expired token(使用過(guò)期令牌發(fā)出同時(shí) API 請(qǐng)求時(shí)如何避免多個(gè)令牌刷新請(qǐng)求)
JWT not decoding quot;JWT malformedquot; - Node Angular(JWT 未解碼“JWT malformed;- 節(jié)點(diǎn)角度)
How to invalidate a JWT token with no expiry time(如何使沒(méi)有到期時(shí)間的 JWT 令牌無(wú)效)
Authorization header in img src link(img src 鏈接中的授權(quán)標(biāo)頭)
主站蜘蛛池模板: 亚洲va在线va天堂va狼色在线 | 欧美a在线 | 成人免费网站 | 日韩亚洲视频在线 | 日韩高清一区 | www.蜜桃av| 日本高清视频在线播放 | 日韩久久中文字幕 | 青青草av | 日韩中文字幕一区 | 国产精品区二区三区日本 | 一区二区高清在线观看 | 在线观看成年视频 | 欧美日韩国产一区二区三区不卡 | 亚洲国产精品一区二区三区 | 国产精品一区二区福利视频 | av网站在线免费观看 | 日韩免费1区二区电影 | 欧美日韩国产精品 | 波霸ol一区二区 | 99精品久久久久久 | 午夜影院在线观看视频 | 久草新在线 | 亚洲一区免费 | 美女福利网站 | 水蜜桃久久夜色精品一区 | 日韩福利电影 | 亚洲 精品 综合 精品 自拍 | 天天干天天干 | 超碰成人免费 | 久久久久国产精品 | 亚洲在线电影 | 中文字幕亚洲一区 | 一区二区三区精品视频 | 国产999精品久久久 精品三级在线观看 | 97精品超碰一区二区三区 | 成人午夜影院 | 久久精品手机视频 | 欧美日韩免费一区二区三区 | 成人午夜免费视频 | 日日网|