【问题标题】:Cross-Domain Ajax Calls and maintaining session on Google App Engine跨域 Ajax 调用和在 Google App Engine 上维护会话
【发布时间】:2011-07-28 00:42:31
【问题描述】:

我最近遇到了一堆对 GAE 应用程序进行跨域 ajax 调用的问题,它运行良好,但是,我试图在进行所述服务调用时设置一个 http 会话 ID,它工作正常,除了每次我执行请求时,会话再次为空。我假设这是因为 ajax 调用而不是通过 http 发出请求?我该怎么办?

【问题讨论】:

    标签: ajax google-app-engine session gwt cross-domain


    【解决方案1】:

    会话跟踪通常使用 cookie 完成。如果您使用跨域资源共享 (http://www.w3.org/TR/access-control/),则默认情况下请求中不包含 cookie。为了将 cookie 与您的请求一起发送,请将以下内容添加到您的 XmlHttpRequest:

    var xhr = new XmlHttpRequest();
    if ("withCredentials" in xhr) {
      xhr.withCredentials = "true";
    }
    

    【讨论】:

    • 这有帮助。我还必须将 Access-Control-Allow-Credentials 设置为 true。 它仍然没有保存会话,但我认为这是朝着正确方向迈出的一大步。
    猜你喜欢
    • 2015-11-22
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 2023-03-14
    • 2012-03-08
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    相关资源
    最近更新 更多