我在netlify上部署了我的前端应用程序,在heroku上部署了后端。当我使用桌面PC时,格式数据被发送到数据库,所有功能都正常工作。但是,当我试图在Chrome浏览器或我手机上的其他浏览器上做同样的事情时,数据就不会被发送出去。
以下是前端代码:
await axios.post(
"https://tea-website-backend.herokuapp.com/api/v1/contact-form",
{
name,
email,
msg,
}
);App.js中相应的后端代码:
app.use("/api/v1/contact-form", submitFormRouter);控制器的功能是:
const Contact = require("../models/Contact");
const { StatusCodes } = require("http-status-codes");
const submitForm = async (req, res) => {
const { name, email, message } = req.body;
const contactForm = await Contact.create({ ...req.body });
res.status(StatusCodes.OK).json("Successful");
};
module.exports = {
submitForm,
};我也尝试了fetch,但这些数据并不是从移动浏览器(chrome和其他浏览器,iphone one)发送的,尽管这些功能可以从所有桌面浏览器上运行:
await fetch(
"https://tea-website-backend.herokuapp.com/api/v1/contact-form",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name,
email,
msg,
}),
}
)请给我一些建议。
发布于 2022-06-16 03:48:32
噢!我终于解决了这个愚蠢的错误!我的Schema模型不接受格式数据,因为我试图发送的值不能满足内置验证器的要求。在测试功能时,我没有在前端设置任何验证--因此无法确定到底出了什么问题。不管怎么说,这是大约一天来解决这个错误!
https://stackoverflow.com/questions/72634700
复制相似问题