Inq*_*Tom 6 javascript shopify reactjs next.js shopify-app
按照本教程,我尝试在 Nextjs 中提交表单,但在尝试 POST 到我的 api 路由时收到 405 错误。我尝试过使用 axios 和 fetch api。这看起来应该很简单,但我不确定我哪里出错了。我缺少什么明显的东西吗?谢谢!
/调查/创建
const handleSubmit = async (event) => {
event.preventDefault();
const testData = {
title: surveyTitle,
};
const res = await fetch("/api/survey", {
method: "POST",
body: JSON.stringify({
dataName: testData,
}),
headers: {
"Content-Type": "application/json",
},
});
};
Run Code Online (Sandbox Code Playgroud)
/api/调查
export default function handler(req, res) {
console.log(req.body);
res.status(200).json(JSON.stringify({ name: 'Success' }))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3950 次 |
| 最近记录: |