如何在JavaScript的HTTP头中传递X-Auth-Token

时间:2022-09-07 10:11:02

I have a website which uses Token-based authentication. At first, username and password are sent to log the user in and receive the token. For subsequent calls, I need to include the token as X-Auth-Token in HTTP header.

我有一个使用基于标记的身份验证的网站。首先,用户名和密码被发送来登录用户并接收令牌。对于后续调用,我需要在HTTP头中包含作为x - authm的令牌。

I would like to know how to do that, in vanilla JavaScript or using jQuery. Could you please provide me a sample of code?

我想知道如何做到这一点,用普通的JavaScript或jQuery。你能给我提供一份代码样本吗?

1 个解决方案

#1


27  

In jQuery it would be something like this:

jQuery是这样的:

$.ajax({
   url : myurl,
   headers: {
        'X-Auth-Token' : token
   });

More details on what you can do with $.ajax() are in the docs

有关如何使用$.ajax()的更多细节,请参阅文档

#1


27  

In jQuery it would be something like this:

jQuery是这样的:

$.ajax({
   url : myurl,
   headers: {
        'X-Auth-Token' : token
   });

More details on what you can do with $.ajax() are in the docs

有关如何使用$.ajax()的更多细节,请参阅文档