Kees C. Bakker Kees C. Bakker - 1 year ago 338
jQuery Question

How to get a cookie from an AJAX response?

I have a

request on the same domain and I want to read the cookie. It keeps returning

type: 'GET',
url: myUrl,
success: function(output, status, xhr) {
cache: false

Any ideas? I'm using Chrome for this.

Answer Source

You're looking for a response header of Set-Cookie:


It won't work with HTTPOnly cookies though.


According to the XMLHttpRequest Level 1 and XMLHttpRequest Level 2, this particular response headers falls under the "forbidden" response headers that you can obtain using getResponseHeader(), so the only reason why this could work is basically a "naughty" browser.