我认为该请求没有问题,因为我使用了相同的请求来发布一个新角色并且它成功了。我认为问题出在响应上。
后端使用 Express 和 Node
我有一个更新字符的 API 路由。
router.put('/:id', (req, res, next) => {
const { id } = req.params;
Promise.all([
updateAbilities(id, req.body.abilities, next),
updateCharacter(id, req.body.name, req.body.img, next),
updateShows(id, req.body.shows, next)
])
.then(values => console.log(values, 'are the values received at put request'))
.then(() => res.redirect('/' + id))
.catch(err => next(err));
})
当我使用Postman发送请求时,我得到了完美的响应。
使用 Axios 的 React App 前端
我正在使用Axios在 React App 上执行相同的请求。
export async function updateOne(inputs, cid) {
inputs = {
name: "green latern 2",
abilities: "ring, superpower",
shows: "justice league",
img: "an image",
};
cid = 11;
let err = null
const response = await axios({
method: 'PUT',
url: BASE_URL + cid,
data: inputs
}).catch(e => err = e);
console.log(response, 'was the response');
return;
}
但是这样做时,我收到此错误:
Error: Network Error
createError createError.js:16
handleError xhr.js:83
dispatchXhrRequest xhr.js:80
xhrAdapter xhr.js:12
dispatchRequest dispatchRequest.js:52
promise callback*request Axios.js:61
wrap bind.js:9
updateOne apiCalls.js:36
js apiCalls.js:66
Webpack 22
was the response apiCalls.js:42
代码可以在 GitHub 上找到:https : //github.com/uinstinct/card_builder
如果您需要更多信息,我将提供您需要的信息。请对相同的评论