开发者

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?


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.


If the document is from the same domain and path, use the document.cookie interface If the cookie has the http-only attribute set, it's inaccessible

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜