久久久久久久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)頭)
主站蜘蛛池模板: www.色.com| 欧美电影在线 | 久久精品91久久久久久再现 | 国产精品高清在线 | 国产视频在线一区二区 | 一区二区三区视频在线观看 | 在线国产视频 | 成人在线精品视频 | 欧美黄视频 | 欧美黄色片 | 日本在线中文 | 亚洲毛片一区二区 | 日韩欧美国产精品一区二区 | 亚洲视频在线一区 | 国产精品一区二区三区久久久 | 一区二区三区四区国产 | 99色在线 | 久久久www成人免费无遮挡大片 | 日韩网站在线 | 国产成人99久久亚洲综合精品 | 国产精品国产三级国产aⅴ原创 | 亚洲高清在线 | 完全免费在线视频 | 日韩一区在线视频 | 成年人在线视频 | 日日操av| 国产一级在线观看 | 黄色网址在线播放 | 欧美成年网站 | 日韩久久久一区二区 | 亚洲精品一区二区 | 天天干狠狠 | 国产精品一区二区视频 | 精品日韩| 国产.com | a毛片| 91精品国产综合久久婷婷香蕉 | 欧美国产日韩精品 | 综合网视频 | 9191成人精品久久 | 国产日韩一区二区三区 |