我正在學習聚合物。我無法使用<iron-ajax>
來計算代碼以「發佈」。我使用的是在線檢測的API(https://reqres.in/),我應該得到這個響應回來狀態碼200:聚合物鐵ajax POST方法不起作用
{"token": "QpwL5tke4Pnpja7X"}".
我無法找到一個教程顯示POST
例子。我一直在網上搜索過去的24小時,但一切都是關於GET
,而不是。
如果任何熟悉<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
@Marco沒有問題:) – tony19
你可以延長你的慷慨的一個問題嗎?你能幫我解決這個問題嗎?https://stackoverflow.com/questions/44459901/polymer-iron-ajax-get-method-retrieving-result-from-an-expressjs-route-returning – Marco