我正在使用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)
})
}
};
上述被卡合误差和表示 - 语法错误:JSON解析错误:无法识别的令牌“<”
你的反应似乎并没有成为一个JSON。
更换
.then((response) => response.json())
对于
.then((response) => { console.log('response', response); response.json() })
而检查什么是错的错误之前的响应。