How to pass X-Auth-Token in the HTTP header in JavaScript [closed]
Asked Answered
B

1

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?

Beam answered 12/11, 2013 at 11:39 Comment(3)
are you using ajax, if yes can you share your codeXylophagous
Read this w3.org/TR/XMLHttpRequest/#the-setrequestheader()-methodAdvanced
I can use ajax in the appBeam
N
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

Nottingham answered 12/11, 2013 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.