跨域Ajax在Google App Engine上调用和维护会话 [英] Cross-Domain Ajax Calls and maintaining session on Google App Engine
问题描述
我最近通过一系列的扭结使跨域的ajax调用到一个GAE应用程序,它是精美的工作,但是,我试图设置一个http会话id,当进行所述服务调用,它是工作正常,除了每次我执行请求,会话再次为null。我假设这是因为ajax调用,而不是通过http请求?
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?
推荐答案
会话跟踪通常使用Cookie进行。如果您使用跨源资源共享(http://www.w3.org/TR/access-control/),则默认情况下Cookie不包含在请求中。为了与您的请求一起发送Cookie,请将以下内容添加到您的XmlHttpRequest中:
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";
}
这篇关于跨域Ajax在Google App Engine上调用和维护会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!