jQuery 跨域 AJAX 请求在一个页面上有效,但在另一个页面上无效

jQuery cross-domain AJAX request works on one page, but not another

这是一个我无法弄清楚的奇怪情况。

我正在我的网站上发出跨域 AJAX 请求,从它的 http 域到它的 https 域。我通过两个不同页面上的按钮来执行此操作。在一个页面上,请求工作正常,我可以从 Firebug 看到我的会话 cookie 已正确发送到服务器。在另一个页面上 - 在相同的域和 URL 结构下 - 没有发送 cookie。

例如从 http://www.example.com/en/apples
开始工作 但不适用于 http://www.example.com/en/oranges

代码如下:

var ajaxUrl = "https://www.example.com/en/controller/add/bananas/";

jQuery.ajax({
    type: "GET",
    url: ajaxUrl,
    xhrFields: {
         withCredentials: true
    },
    crossDomain: true,
    success: function(data) {
      console.log("Yay");
    }
  }
);

我的 https 站点响应:

Header add Access-Control-Allow-Origin      "http://www.example.com"
Header add Access-Control-Allow-Credentials "true"

我知道它有效,因为它适用于 /apples,但完全相同的代码不适用于 /oranges!这是怎么回事?

仍然不确定为什么它在一个页面上工作而不在另一个页面上工作,但是我通过 Apache 的 conf.d 文件向 HTTPS 服务器添加更多 headers 来修复它:

<IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin      "http://www.example.com"
    Header add Access-Control-Allow-Credentials "true"
    Header add Access-Control-Allow-Methods     "GET, POST"
    Header add Access-Control-Allow-Headers     "Content-Type, Authorization, X-Requested-With"
    Header add Access-Control-Max-Age           "1000"
</IfModule>

两个页面现在都可以使用了。

同时检查:
Why is jquery's .ajax() method not sending my session cookie?
How do I send a cross-domain POST request via JavaScript?