【发布时间】:2017-03-06 15:32:56
【问题描述】:
我在我的 Polymer 项目中使用 iron-ajax 来登录用户。将用户详细信息发送到数据库后,如果登录成功,我需要返回一个令牌。但是,我在响应时遇到了问题。如果有人可以查看我的代码并告诉我我缺少什么,那就太好了。
目前,当我输出 repos 属性时,控制台返回我未定义。下面是我的 Iron-ajax 我的属性的代码以及当用户发送详细信息时调用的函数。
此外,我添加了我想要返回的内容。
<dom-module id="login-form">
<template>
<iron-ajax
id="requestUser"
url="http://api.dev/oauth/token"
handle-as="json"
method="POST"
content-type="application/json"
body='{
"grant_type": "password",
"client_id": 2,
"client_secret": "KyHacYa2Q7DCTVLaDe1RSnvTlTI20CrmYb7FXujb",
"username": "user1@test.com",
"password": "1111",
"scope": "*"}'
last-response="handleResponse"></iron-ajax>
</template>
<script>
Polymer({
is: 'login-form',
properties: {
repos: {
type: Array
},
},
//On-tap loginTheUser runs
loginTheUser: function() {
this.$.requestUser.generateRequest();
},
handleResponse: function (data) {
this.repos = data.details.response;
console.log(this.repos);
},
</script>
</dom-module>
以下是我尝试返回的令牌:
{
"token_type": "Bearer",
"expires_in": 3155673599,
"access_token": "eyJ0eXAiOiJKV1...",
"refresh_token": "271VWcUXisybg="
}
【问题讨论】:
标签: json ajax polymer token polymer-1.0