Jquery Ajax CORS +仅 Http Cookie
我已经在我当前的项目中使用了 CORS,尽管我似乎无法正常工作的一件事是 cookie。
现在我得到了 cookie,服务器发出它并将其发送下来,firefox 接受它,我可以在 firebug cookies 部分看到它。然而,当我对该服务进行后续调用时,它似乎没有在标头中发送 cookie...
GET /some/entity/ HTTP/1.1
Host: localhost:1837
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: */*
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost:6879
Origin: http://localhost:6879
我需要对我的 ajax 调用执行任何特殊操作吗?
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
xhrFields: { withCredentials: true }
};
$.ajax(ajaxOptions);
I have got CORS working on my current project, although one thing I cannot seem to get working correctly is the cookies.
Now I get the cookie fine, the server issues it and sends it down and firefox accepts it, I can see it in the firebug cookies section. However when I make subsequent calls to that service it doesnt seem to send the cookie in the header...
GET /some/entity/ HTTP/1.1
Host: localhost:1837
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: */*
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost:6879
Origin: http://localhost:6879
Do I need to do anything special with my ajax call?
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
xhrFields: { withCredentials: true }
};
$.ajax(ajaxOptions);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 beforeSend 属性而不是 xhrFields。对于您的情况:
您可以在此处了解更多信息:使用跨域帖子发送凭据?
Try using the beforeSend property instead of xhrFields. In your case:
You can learn more here: Sending credentials with cross-domain posts?