I'm doing an AJAX call and setting a cookie in the user browser in the response (the server code sets the cookie). I noticed in the success callback from the ajax, the cookie is not available. When I look in
document.cookie the new cookie is not there.
My question, when can I be certain that the new cookie is there? if not in the success callback, maybe on a timeout with 100ms? 1s? indeterminate?
Best How To :
Cookies are passed as HTTP headers, both in the request and in the response.
When you do an ajax call and set a cookie, that cookie will only be available in the browser after a reload / redirect happens, and new headers are gotten from the server containing the newly set cookie.
In other words, a timeout, callback or anything else won't work, you have to reload the page to get the new headers.