如何从一个Ajax响应饼干吗? [英] How to get a cookie from an AJAX response?
问题描述
我有一个 $。阿贾克斯
在同一个域的要求,我想读取cookie。它使返回空
。
I have a $.ajax
request on the same domain and I want to read the cookie. It keeps returning null
.
$.ajax({
type: 'GET',
url: myUrl,
success: function(output, status, xhr) {
alert(xhr.getResponseHeader("MyCookie"));
},
cache: false
});
任何想法?我使用的是Chrome浏览器这一点。
Any ideas? I'm using Chrome for this.
推荐答案
您正在寻找设置Cookie的响应头
:
xhr.getResponseHeader('Set-Cookie');
这不会仅Http饼干虽然工作。
It won't work with HTTPOnly cookies though.
根据<一href="https://dvcs.w3.org/hg/xhr/raw-file/default/xhr-1/Overview.html#the-getresponseheader()-method"相对=nofollow> XMLHtt prequest 1级和 XMLHtt prequest 2级,这个特殊的响应头的禁止的响应报头,您可以使用获得 getResponseHeader()
下的瀑布,所以唯一的原因,这可以工作基本上是一个调皮的浏览器。
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.
这篇关于如何从一个Ajax响应饼干吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!