Mar*_*usz 9 cookies ajax jquery cors
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/
Run Code Online (Sandbox Code Playgroud)
响应标题:
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=/
Run Code Online (Sandbox Code Playgroud)
码:
$.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
},
});
Run Code Online (Sandbox Code Playgroud)
在Firefox中一切都很好.Chrome未设置Cookie.仅当域字段被删除时,所有浏览器都在运行.我可以看到在下一个请求中(在设置cookie之后)cookie出现在标题中.响应设置cookie后的firefox请求示例(当响应有域字段时):
Cookie: Auth=l_hash=123456&user=xyz&remember_me=false
Run Code Online (Sandbox Code Playgroud)