domain使用跨站点请求添加文件时,我无法设置cookie 。我正在尝试通过jquery ajax调用请求来实现这一点。
是否可以使其在firefox以外的其他浏览器中运行?
一些请求标头:
Accept:application/json, text/javascript, */*; q=0.01
Content-Length:55
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:53862
Origin:http://localhost:54265
Referer:http://localhost:54265/
响应标题:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:x-requested-with, origin, content-type, accept, Proxy-Connection
Access-Control-Allow-Methods:GET,POST,PUT,OPTIONS, DELETE
Access-Control-Allow-Origin:http://localhost:54265
Set-Cookie:Auth=l_hash=123456&user=xyzl&remember_me=false; expires=Fri, 18 Jan 2013 13:42:10 GMT; domain=localhost; path=/
码:
$.ajax({
type: "PUT",
url: apiHost + "api/account/login/",
data: $("#loginBarForm").serialize(),
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
crossDomain: true,
xhrFields: {
withCredentials: true
},
});
Firefox中一切都很好。Chrome未设置Cookie。仅在删除域字段的情况下,所有功能都可以在每个浏览器上使用。我可以看到,在下一个请求(设置cookie后)中,cookie出现在标题中。来自响应设置cookie后(响应具有域字段)的firefox请求的示例:
Cookie: Auth=l_hash=123456&user=xyz&remember_me=false