2

Ajax.Request(からPrototype.js)に設定xhr.transport.withCredentialsするように指示する必要があります(trueクロスサイトリクエストヘッダーでCookieを有効にするため)。私は試して失敗しました:

Ajax.Request('http://otherSubdomain.host:port/', {
    onCreate: function(request){
        request.transport.withCredentials = true;
    }
});

Access-Control-Allow-Originが設定され、request成功しましたが、Cookieは送信されませんでした

指摘するのは嫌ですjquery が、ここでははるかに簡単なようexample solutionです。

4

2 に答える 2

3

Ajax.Request次のようにパッチを適用してみてください。

Ajax.Request.prototype.request = Ajax.Request.prototype.request.wrap(function(request, url) {
  if (this.options.withCredentials) {
    this.transport.withCredentials = true;
  }
  request(url);
});

そして、追加のオプションがありますwithCredentials

new Ajax.Request('example.com', {
    withCredentials: true
});
于 2012-11-30T08:05:06.817 に答える
1

ビクターの答えを少し改善しました。

'open'と'send'の間にwithCredentialsを設定する必要があるIEの修正と、jQueryajaxオプションとの整合性を確保します。

Ajax.Request.prototype.setRequestHeaders = Ajax.Request.prototype.setRequestHeaders.wrap(function(setHeaders) {
  setHeaders();
  if (this.options.xhrFields) Object.extend(this.transport, this.options.xhrFields);
});

そしてそれを使用するには:

new Ajax.Request('example.com', {
  xhrFields: {
    withCredentials: true
  }
});
于 2016-07-21T09:06:55.297 に答える