Cross-Domain Ajax Calls and maintaining session on Google App Engine

纵然是瞬间 提交于 2020-01-04 02:44:11

问题


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:


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";
}


来源:https://stackoverflow.com/questions/5519479/cross-domain-ajax-calls-and-maintaining-session-on-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!