Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
axios.post()发送数据并在Node.js中的函数中接收数据时出错_Node.js_Reactjs_Mongodb_Api_Axios - Fatal编程技术网

axios.post()发送数据并在Node.js中的函数中接收数据时出错

axios.post()发送数据并在Node.js中的函数中接收数据时出错,node.js,reactjs,mongodb,api,axios,Node.js,Reactjs,Mongodb,Api,Axios,我将axios.post()中的数据发送到Node.js中的函数。函数未接受数据的所有参数。 我犯了什么错 这是React中的代码: axois.post('http://localhost:9000/question/create', **question**) .then((res) => { console.log('res.data -> ', res.data); // The res.dat

我将axios.post()中的数据发送到Node.js中的函数。函数未接受数据的所有参数。 我犯了什么错

这是React中的代码:

            axois.post('http://localhost:9000/question/create', **question**)
            .then((res) => {
                console.log('res.data -> ', res.data);  // The res.data sends all the data (see it in the console)
            }).catch((error) => {
                console.log('error -> ', error);
            });
这是Node.js中的代码:

    console.log('req -> ', req.body); // The req.body didn't get all the parameters of the data that came to it.
  dataQuestion.create(**req.body**, (error, data) => {
      if (error) {
          return next(error)
      } else {
          console.log(data)
          res.json(data)
      }
  });
}); ```

Appreciates any answer ...
Thank you!

使用axios执行post时,需要第二个参数,它是post请求的主体

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });