Ich habe Probleme mit Eisen-Ajax auf Polymer 2.0. Mein Code basiert auf einem Polymer 1.0 und ich versuche es anzupassen. Ich sende meine Form durch einen POST wie folgt aus:Iron-Ajax 401 nicht autorisierte oder CORS Problem
Vorlage:
<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>
Code:
_setReqBody() {
this.$.registerLoginAjax.body = this.formData;
}
postLogin() {
this.$.registerLoginAjax.url = 'http://localhost:3001/sessions/create';
this._setReqBody();
this.$.registerLoginAjax.generateRequest();
}
Eisen-Ajax-Setup:
<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>
Und wenn ich tun Ich erhalte den folgenden Fehler:
POST http://localhost:3001/sessions/create 400 (Bad Request)
Und wenn ich diese Zeile auf dem Eisen-Ajax:
with-credentials="true"
Der Fehler, da es ein CORS Problem scheint, ist:
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.
Was mache ich falsch?
Was Sie auf Server-Seite haben? Funktioniert es richtig mit Polymer 1. *? – Dmitry