![](/img/trans.png)
[英]Calling an action to update local storage (without API call) - redux persist, react native
[英]Error in calling POST api in react native by handling action in redux
我正在使用POST api调用来获取一些数据,其中有数据和标头的令牌值,但是响应不佳,我检查了许多文档,但无法弄清楚错误,这是代码:
export const shareUserProfileHandler = (sharedReceiverData) => {
return dispatch => {
let formData = new FormData();
for (let key in sharedReceiverData) {
formData.append(key, sharedReceiverData[key]);
}
let requestConfig = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'Authorization': 'Token 97a74c03004e7d6b0658b14ddb'
},
body: formData
};
fetch(`http://api.com`, requestConfig)
.then(response => response.json())
.then(response => {
alert('share user card api worked')
})
.catch(error => {
alert('api error ' + error)
})
}
};
上面是捕获错误并显示-SyntaxError:JSON解析错误:无法识别的令牌“ <”
您的响应似乎不是JSON。
更换
.then((response) => response.json())
对于
.then((response) => { console.log('response', response); response.json() })
并检查错误之前响应的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.