0

It is said that setting cookie through javascript doesn't travel through the HTTP header.What could be the reason behind this?Why javascript cookie dont travel through HTTP header?

document.cookie ='ppkcookie1=testcookie';

2 Answers 2

1

Cookies set by Javascript are sent in the HTTP header, but not at the time when you set the cookie. It will be included in the header the next time you make a request to the server.

Sign up to request clarification or add additional context in comments.

2 Comments

But a link here says it wont travel through http header and is non-HTTP method
@Maizere: The article is talking about the set-cookie header which is used by the server to tell the browser to set a cookie. When you set it using Javascript it's set directly in the browser, so it will be sent in the cookie header to inform the server about it.
1

If you fix the syntax error (the string literal is was, until the question was edited, missing its closing '), then it does (although, obviously, not until the next HTTP request is made).

2 Comments

But a link here says it wont travel through http header and is non-HTTP method
That is discussing the Set-Cookie response header, not the Cookie request header. If you set a cookie with JavaScript instead of HTTP then the HTTP header setting the cookie won't be used. That doesn't change what the browser does with cookies (i.e. send them back to the server in each request) one they have been set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.