0
私はバックボーンで作られたアプリを持っています。コレクションが同期しようとすると、私は次のエラーを取得する:CORSを使用し、資格情報を持たないバックボーンコレクション
XMLHttpRequest cannot load https://someserver/menu.json. The value of
the 'Access-Control-Allow-Origin' header in the response must not be
the wildcard '*' when the request's credentials mode is 'include'.
Origin 'http://www.otherdomain.com' is therefore not allowed access.
The credentials mode of requests initiated by the XMLHttpRequest is
controlled by the withCredentials attribute.
コレクションだけでモデルやURLを指定して、簡単な解析を持っています。
次のように私は、同期メソッドをオーバーライドしてみました:アプリが初期化するとき
(function() {
var proxiedSync = Backbone.sync;
Backbone.sync = function(method, model, options) {
options || (options = {});
if (!options.crossDomain) {
options.crossDomain = true;
}
if (!options.xhrFields) {
options.xhrFields = {withCredentials:true};
}
return proxiedSync(method, model, options);
};
})();
私はこの機能を実行します。ただし、エラーは同じままです。私は異なる組み合わせ(withCredentials:false
、withCredentials
などの行を削除してみました)を成功させました。
サービスは「*」を提供するように設定されています。
この問題を解決する方法はありますか?
サービスの再設定やブラウザセキュリティの無効化はオプションではありません。
回答ありがとうございます。残念ながら、サーバーを再構成することはできず、*に設定されています。私はまだwithCredentialsオプションを無効にする方法を取得しません。 –
@ grahamo'donnelどのバージョンのjQueryを使用していますか?これは1.5で追加されました。そして、このコードはいつ実行されますか? –
j jQuery v2.1.4を使用しています。スクリプトsrcタグの直後に、index.htmlにsyncスクリプトを追加しました。 –