不随 xmlhttprequest 发送的参数

Parameters not sent with xmlhttprequest

我正在尝试从客户端发送带有 xmlHttpRequest 的内容,但我无法在服务器端接收这些参数。

在服务器端设置参数并在客户端检索它们工作正常,但是当我尝试进入服务器端时,我试图在客户端设置的参数总是空的值/未定义。

node.js server side response on req.params =
...
 ( params: [] } )
...

知道为什么它不在服务器端检索参数吗?在服务器端,我使用 app.post('/delete', function(req, res){ ..) 我尝试 console.log req.params 应该使用以下设置客户端代码(但没有):

https://jsfiddle.net/user979979/ea2w1sn8/

谢谢!

您需要在服务器端使用 BodyParser 中间件。 在你的 app.js 中,导入 bodyparser import bodyParser from 'body-parser';

然后写 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false }));

现在您将在 req.body 中获取您的 post 参数并在 req.query

中获取参数