Can an AJAX response set a cookie?

Billworth Vandory picture Billworth Vandory · Jul 27, 2010 · Viewed 137.5k times · Source

Can an AJAX response set a cookie? If not, what is my alternative solution? Should I set it with Javascript or something similar?

Answer

Strelok picture Strelok · Jul 27, 2010

According to the w3 spec section 4.6.3 for XMLHttpRequest a user agent should honor the Set-Cookie header. So the answer is yes you should be able to.

Quotation:

If the user agent supports HTTP State Management it should persist, discard and send cookies (as received in the Set-Cookie response header, and sent in the Cookie header) as applicable.