最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用获取发送表单数据

IT培训 admin 4浏览 0评论

使用获取发送表单数据

我正在尝试使用提取发送表单数据。我有以下代码:

var toSend = new FormData();
toSend.append('person', 'Peter');
toSend.append('age', '22');
toSend.append('thistext', 'smart');

fetch('http://localhost:3000/sendform', {
    method: 'POST',
    body: toSend
}).then(res => console.log(res));

然后我尝试使用以下代码在Express的后端读取表单数据:

app.post("/sendform", function(req, res) {
    console.log("processing form data");
    console.log(req.body);
    res.status(200).send("received");
});

我有人体分析仪等。但是,req.body是一个空对象。有人可以帮忙解决吗?

回答如下:

尝试此代码,

let payload = {
    person: "peter",
    age: "22",
    thistext: "smart"
};

fetch("http://localhost:3000/sendform", {
    method: "POST",
    body: JSON.stringify(payload)
}).then(res => console.log(res));

使用获取发送表单数据

我正在尝试使用提取发送表单数据。我有以下代码:

var toSend = new FormData();
toSend.append('person', 'Peter');
toSend.append('age', '22');
toSend.append('thistext', 'smart');

fetch('http://localhost:3000/sendform', {
    method: 'POST',
    body: toSend
}).then(res => console.log(res));

然后我尝试使用以下代码在Express的后端读取表单数据:

app.post("/sendform", function(req, res) {
    console.log("processing form data");
    console.log(req.body);
    res.status(200).send("received");
});

我有人体分析仪等。但是,req.body是一个空对象。有人可以帮忙解决吗?

回答如下:

尝试此代码,

let payload = {
    person: "peter",
    age: "22",
    thistext: "smart"
};

fetch("http://localhost:3000/sendform", {
    method: "POST",
    body: JSON.stringify(payload)
}).then(res => console.log(res));

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论