[英]Axios Network error on post request React.js but works on Postman
[英]Network Error when sending request to url from React Js using Axios
我正在尝试在我的 react js 上使用 axios 发送删除请求。 我已经在 heroku 上部署了 node js 服务器并将其用作我的链接。 以下是部署到heroku的server.js中的代码。
const deletePhoto = async (req, res) => {
try {
const file = bucket.file(req.params.name);
file.delete();
res.status(200).send("Photo deleted from bucket").end();
} catch (err) {
res
.send(500)
.send("Error occurred " + err)
.end();
}
};
下面的代码是我使用 react.js 和 axios 发送的请求。
const deleteImage = (docId) => {
let url =
"https://photobook-server-khushboo1028.herokuapp.com/files/" + docId;
console.log(url);
axios
.delete(url)
.then((response) => {
console.log(response);
alert("Successfully deleted image");
})
.catch((error) => {
alert(error);
console.log(error);
});
};
我收到的错误是这样的:
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:117)
我使用的 axios 版本是“0.23.0”。
我什至尝试通过执行app.use(cors)
在我的 node.js 服务器上添加 cors。 请帮帮我。 任何建议表示赞赏。 谢谢你
name
是否与你的 url 中的docId
相对应?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.