【发布时间】:2017-02-07 13:16:45
【问题描述】:
我正在为我的 react native 应用程序制作登录页面。当我的用户名和密码有效和无效时,我的 api 会发送不同的响应。所以我想跟踪我的响应状态并将其保存在某个状态变量中,然后相应地执行功能。请建议我这样做。
doSignUp() {
console.log("inside post api");
fetch('MyApiUrl', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
password: this.state.password,
email:this.state.email,
name: this.state.firstname,
last_name :this.state.last_name,
mobile:this.state.mobile,
ssn:"2222222"
})
}).then((response) => {console.log('response:',response.status);
response.json()}
.then((responseData) => {
console.log("inside responsejson");
console.log('response object:',responseData)
console.log('refresh token:',responseData[0].token.refresh_token)
console.log('access token:',responseData[0].token.access_token);
}).done();
}
【问题讨论】: