Polymer 2.0でiron-ajaxを使用する際に問題が発生しています。私のコードはPolymer 1.0に基づいており、私はそれを適応させようとしています。私はこのようなPOSTを通じて自分のフォームを送信します。Iron-ajax 401不正またはCORSの問題
テンプレート:
<div class="wrapper-btns">
<paper-button raised class="primary" on-tap="postLogin">Log In</paper-button>
<paper-button class="link" on-tap="postRegister">Sign Up</paper-button>
</div>
コード:
_setReqBody() {
this.$.registerLoginAjax.body = this.formData;
}
postLogin() {
this.$.registerLoginAjax.url = 'http://localhost:3001/sessions/create';
this._setReqBody();
this.$.registerLoginAjax.generateRequest();
}
鉄 - Ajaxのセットアップ:
<iron-localstorage name="user-storage" value="{{storedUser}}"></iron-localstorage>
<app-data key="userData" data="{{storedUser}}"></app-data>
<iron-ajax
id="registerLoginAjax"
method="post"
content-type="application/json"
handle-as="text"
on-response="handleUserResponse"
on-error="handleUserError"></iron-ajax>
そして、私はを次のエラーが表示されます。
POST http://localhost:3001/sessions/create 400 (Bad Request)
そして私は鉄のAjaxにこの行を使用します。
with-credentials="true"
エラーそれはそうとはCORSの問題である:
XMLHttpRequest cannot load http://localhost:3001/sessions/create . Response to preflight request doesn't pass access control check: 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://127.0.0.1:8081 ' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
私が間違って何をしているのですか?
は、サーバー側では何がありますか?それはポリマー1で正しく働いていますか?*? – Dmitry