title: Trying to send post request from ejs file with some data to express server but req.body is returning undefined
body: <p>I am using jquery ajax to send post request to my server along with some data that will be included in my database. The post object is defined in the script of my ejs file.</p>
  <pre><code>&lt;script&gt;
          const button = document.getElementById('started');
  
          button.addEventListener(&quot;click&quot;, (e) =&gt; {
              e.preventDefault();
              var post = {};
  
              if (button.innerHTML === &quot;Start Task&quot;) {
                  button.innerHTML = &quot;End Task&quot;;
                  localStorage.startTime = new Date();
              }
  
              else if (button.innerHTML === &quot;End Task&quot;) {
                  button.innerHTML = &quot;Submit&quot;;
                  localStorage.endTime = new Date();
              }
  
              else if (button.textContent === &quot;Submit&quot;) {
                  post.title = $('#title').val();
                  post.desc = $('#desc').val();
                  post.startTime = Date.parse(localStorage.startTime);
                  post.endTime = Date.parse(localStorage.endTime);
  
                  console.log(post); //Here, the post object is defined
  
                  $.ajax({ url: '/home', type: 'POST', data: post })
                      .then(res =&gt; console.log(&quot;successfully posted&quot;))
                      .catch(err =&gt; console.log(&quot;error&quot;, err));
              }
          });
  &lt;/script&gt;
  </code></pre>
  <p>This is my route that handles the post request</p>
  <pre><code>app.post(&quot;/home&quot;, (req, res) =&gt; {
      Posts.create(req.body.post, (err, done) =&gt; {
          if (err) {
              console.log(&quot;Error occured while posting to home&quot;, err);
              res.redirect(&quot;/home&quot;);
          } else {
              console.log(&quot;Task Added&quot;, req.body.post, done);
              res.redirect(&quot;/home&quot;);
          }
      })
  });
  </code></pre>
  <p>Here, req.body.post is undefined for some reason. Also, I have bodyparser set up so that is not the issue. Is there something wrong with my ajax request?</p>