title: Postman post request works but ajax post does not. Have checked client side js over and over
body: <p>first question ever on stackoverflow and boy do I need an answer. My problem is that I have an endpoint to create an item, and it works when I send a POST request with Postman. I'm using node and express: </p>
  
  <pre><code>router.post("/", jwtAuth, (req, res) =&gt; {
    console.log(req.body);
    const requiredFields = ["date", "time", "task", "notes"];
    requiredFields.forEach(field =&gt; {
      if (!(field in req.body)) {
        const message = `Missing \`${field}\` in request body`;
        console.error(message);
        return res.status(400).send(message);
      }
    });
    Task.create({
      userId: req.user.id,
      date: req.body.date,
      time: req.body.time,
      task: req.body.task,
      notes: req.body.notes
    })
      .then(task =&gt; res.status(201).json(task.serialize()))
      .catch(err =&gt; {
        console.error(err);
        res.status(500).json({ message: "Internal server error" });
      });
  });
  </code></pre>
  
  <p>That endpoint works when I send with Postman and the req body logged with the right values.</p>
  
  <p>But when I send my ajax request, my server code logs the req.body as an empty object ('{}'). Because Postman works I believe the problem is with my client side javascript but I just cannot find the problem. I and others have looked over it a million times but just can't find the problem. Here is my client side javascript:</p>
  
  <pre><code>//User submits a new task after timer has run
  function handleTaskSubmit() {
    $(".submit-task").click(event =&gt; {
      console.log("test");
      const date = $(".new-task-date").text();
      const taskTime = $(".new-task-time").text();
      const task = $(".popup-title").text();
      const notes = $("#task-notes").val();
      $(".task-notes-form").submit(event =&gt; {
        event.preventDefault();
        postNewTask(date, taskTime, task, notes);
      });
    });
  }
  
  function postNewTask(date, taskTime, task, notes) {
    const data = JSON.stringify({
      date: date,
      time: taskTime,
      task: task,
      notes: notes
    });
  //Here I log all the data. The data object and all its key are defined
    console.log(data);
    console.log(date);
    console.log(taskTime);
    console.log(task);
    console.log(notes);
    const token = localStorage.getItem("token");
    const settings = {
      url: "http://localhost:8080/tasks",
      type: "POST",
      dataType: "json",
      data: data,
      contentType: "application/json, charset=utf-8",
      headers: {
        Authorization: `Bearer ${token}`
      },
      success: function() {
        console.log("Now we are cooking with gas");
      },
      error: function(err) {
        console.log(err);
      }
    };
    $.ajax(settings);
  }
  
  handleTaskSubmit();
  </code></pre>