我正在使用AJAX调用另一个服务的API,该API应该返回一个cookie,以便我可以在浏览器中设置它,以允许我进行其余的API调用。
然而,虽然响应标头包括“Set-Cookie”标头,但实际上没有设置任何Cookie。我正在使用Google Chrome。
以下是响应标头:
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Connection:keep-alive
Content-Encoding:gzip
Content-Length:37
Content-Type:application/json
Date:Thu, 25 Jun 2015 18:27:37 GMT
Expires:Thu, 25 Jun 2015 18:27:36 GMT
Server:nginx/1.4.6 (Ubuntu)
Set-Cookie:sessionid=67cb9796aa794a4975b28876ea6dd3d5; expires=Thu, 09-Jul-2015 18:27:37 GMT; httponly; Max-Age=1209600; Path=/
Vary:Cookie
这里是AJAX调用:
$.ajax({
type: "POST",
crossDomain: true,
contentType: 'text/plain',
data: data,
url: urlhere
success: function(result, status, xhr){
console.log('hi');
console.log(xhr.getAllResponseHeaders());
},
error: function(xhr){
console.log(xhr.status);
console.log(xhr.statusText);
}
});
Chrome 资源页面还显示没有设置 cookie。非常感谢任何帮助!