Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the Set-Cookie value from an HTTP response header in JavaScript?

I'm using jQuery's ajax() method to make some asynchronous server calls and want to catch the case where a call fails because the session has timed out.

From looking at the response headers in this case, I see that they include

Set-Cookie: SMSESSION=LOGGEDOFF

which seems like a pretty reliable test. But calling getAllResponseHeaders on the XMLHttpRequest object passed to jQuery's error callback apparently returns an empty string, and I'm having trouble figuring out any other way of getting that header information.

Is this possible?

like image 545
Dan Tao Avatar asked Aug 25 '11 21:08

Dan Tao


1 Answers

If you read the W3 XHR spec you'll see that they don't allow you to access the set-cookie response header via a getAllResponseHeaders('Set-Cookie') call.

See 4.7.3 The getResponseHeader() method:

Bullet point 3: "If header is a case-insensitive match for Set-Cookie or Set-Cookie2, return null."

http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders%28%29-method

jfriend00 also left this response in the comments above but I thought this question could use a legitimate answer.

like image 91
Andre Avatar answered Oct 22 '22 01:10

Andre