title: Back-end API receiving empty request body when making request from front-end
body: <p>I am building Web application on my localhost.</p>
  
  <p>The front-end is Reactjs framework, running in localhost:3000</p>
  
  <p>The back-end is nodejs + Express, running in localhost:4000</p>
  
  <p>Now, I have created the API below:</p>
  
  <pre><code>router.post('/register', function (req, res) {
      console.log(req.body); // {}, why it is empty?
  
      // create new instance, save it to database
      User.create(req.body).then(function () {
          res.send('success');
      });
  });
  </code></pre>
  
  <p>The front-end part is:</p>
  
  <pre><code>handleSubmit = (e) =&gt; {
          e.preventDefault();
          this.props.form.validateFieldsAndScroll((err, values) =&gt; {
              if (!err) {
                  console.log('Received values of form: ', values); // value is not empty, I have tested! So we did send something to the API
  
                  const input = JSON.stringify({
                      username: values.username,
                      password: values.password,
                  });
  
                  console.log(input);
                  $.ajax({
                      url: `${API_ROOT}/register`,
                      method: 'POST',
                      data: JSON.stringify({
                          username: values.username,
                          password: values.password,
                      }),
                  }).then((response) =&gt; {
                      if (response === 'success') {
                          this.props.history.push('/login');
                      } else {
                          console.log('do not jump');
                      }
  
                  });
              }
          });
      }
  </code></pre>
  
  <p>I have tested the API by the postman, I can add users to MongoDB, so the API is good. </p>
  
  <p>I have console.log what I sent to API, it is not empty, however, backend API receive d empty request body. I have already fixed the "Access-Control-Allow-Origin" issue, so I think I do send something to the API, but backend API received empty request body.</p>