我在后端使用ReactJS和nodeJS。
我正在以这种方式处理表单提交:
const [email, setEmail] = useState({
name: "",
subject: "",
message: "",
address: "",
});
const sendHandler = async e => {
e.preventDefault();
setSending(true);
const res = await fetch("/api/send-mail", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(email),
});
...rest of the code
};
But somehow, when sendHandler
function is executed, get request is made instead of post.
P.S i'm making request from localhost to https website.