Cross-Domain Ajax Calls and maintaining session on

2019-07-06 00:21发布

I have recently worked through a bunch of kinks making cross-domain ajax calls to a GAE app and it is working beautifully, however, I am trying to set an http session id when making said service call and it is working fine, except that every time I perform the request, the session is null again. I'm assuming that this is because an ajax call and not making the request over http? How can I go about this?

1条回答
2楼-- · 2019-07-06 00:57

Session tracking is usually done with cookies. If you are using Cross-Origin Resource Sharing (http://www.w3.org/TR/access-control/), then cookies are not included in the request by default. In order to send cookies along with your request, add the following to your XmlHttpRequest:

var xhr = new XmlHttpRequest();
if ("withCredentials" in xhr) {
  xhr.withCredentials = "true";
}
查看更多
登录 后发表回答