私はPolymerを学習しています。私は<iron-ajax>
を使って "投稿"するコードを理解することができません。私は(https://reqres.in/)オンラインテストのAPIを使用している、と私はステータスコード200とバックこの応答を受け取る必要があります:私はPOST
例を示すチュートリアルを見つけることができませんでしたPolymer iron-ajax POSTメソッドが動作しない
{"token": "QpwL5tke4Pnpja7X"}".
。私は過去24時間オンラインで検索していますが、すべてGET
で、POST
ではありません。
<iron-ajax>
をよく知っている人であれば、私のコードを見直して正しいコードを書く方法を理解できたら、私のような初心者にとっては非常に役立ちます。
- 私のコードは
body
プロパティで正しいですか? 応答は
200
ステータスコードまたはトークンですか?<!-- @license Copyright (c) 2016 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> <link rel="import" href="../bower_components/polymer/polymer-element.html"> <link rel="import" href="shared-styles.html"> <link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/iron-ajax/iron-ajax.html"> <dom-module id="my-view2"> <!--test using this data: { "email": "[email protected]", "password": "cityslicka" }--> <template> <iron-ajax> auto method="post" url="https://reqres.in/api/login" handle-as="json" content-type="application/json" body =[{"email": "[email protected]", "password": "cityslicka"}] on-response={{handleResponse}} </iron-ajax> <!--Handle response--> <p> response handling code goes here, how to show the response from the server here?</p> <p> It should show: {"token": "QpwL5tke4Pnpja7X"} </p> <div> <p> {{handleResponse}} </p> </div> </template> <script> class MyView2 extends Polymer.Element { static get is() { return 'my-view2'}; static get proporties() { return { handleResponse: { type: Object, notify: true, readOnly: true } }; } } window.customElements.define(MyView2.is, MyView2); </script> </dom-module>
私の良さは、そのような完全で優れた答えでした。どうもありがとうございます。私はより詳細な答えを求めることができませんでした。乾杯。 – Marco
@マルコ問題はありません:) – tony19
あなたはもう1つの質問のためにあなたの寛大さを広げることができますか?この問題を手伝ってもらえますか?https://stackoverflow.com/questions/44459901/polymer-iron-ajax-get-method-retrieving-result-from-an-expressjs-route-returning – Marco