我是在跨域的情况下操作。在登录期间,远程服务器将返回set-cookie头以及Access-Control-Allow-Credentials设定为真。
下一个对远程服务器的Ajax调用应该使用此cookie。
CORS‘sAccess-Control-Allow-Credentials是否允许跨域日志记录。查帐https:/developer.mozilla.org/en/HTTP_Access_Control举个例子。
对我来说,这似乎是JQuery中的一个bug(或者至少在下一个版本中是将要出现的特性)。
最新情况:
文档中的示例如下:$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}});
服务器正确地响应此请求也很重要。在这里复制@Frédéric和@Pebbl的精彩评论:
Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *
因此,当请求是:Origin: http://foo.exampleCookie: pageAccess=2
服务器响应时应:Access-Control-Allow-Origin: http://foo.exampleAccess-Control-Allow-Credentials: true[payload]