18

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.

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

Sam R.
  • 16,027
  • 12
  • 69
  • 122
GibboK
  • 71,848
  • 143
  • 435
  • 658

1 Answers1

31

In jQuery it would be something like this:

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

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

asiviero
  • 1,225
  • 10
  • 16