我正在使用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解析错误:无法识别的标记‘<’
发布于 2019-02-03 23:05:12
您的响应似乎不是JSON。
替换
.then((response) => response.json())
为
.then((response) => { console.log('response', response); response.json() })
并在出现错误之前检查响应中的错误。
https://stackoverflow.com/questions/54504094
复制相似问题