Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top