Fetch post with body data not working params empty
<p>I am trying to rewrite my ajax call to fetch:</p>

<p>Ajax:</p>

<pre><code>  $.post({
    context: this,
    url: "/api/v1/users",
    data: { 
      user: 
        {
          email: email,
          password: password
        } 
    }
  }).done((user) =&gt; {
  }).fail((error) =&gt; {
  })
</code></pre>

<p>Fetch:</p>

<pre><code>  fetch('/api/v1/users', {  
  method: 'POST',
  headers: {
    "Content-Type": "application/json"
  },      
    body: { 
    "user" : 
      {
        "email" : email,
        "password" : password
      } 
  }
  })
  .then(res =&gt; {  
    if (res.status !== 200) { {
        console.log("error")
      })          
    } else {
      res.json().then(data =&gt; {
        console.log(data)
      })
    }
  })
</code></pre>

<p>I am getting an error empty params ~ bad request from my server.</p>

<p>I also found this way to do it, but in this code below I am getting an error: Unexpected token.</p>

<pre><code>  var payload = { 
    "user" : 
      {
        "email" : email,
        "password" : password
      } 
  };

  var data = new FormData();
  data.append( "json", JSON.stringify( payload ) );

  fetch('/api/v1/users', {  
  method: 'POST',
  headers: {
    "Content-Type": "application/json"
  },      
    body: data
  })
</code></pre>

<p>How can I rewrite the ajax request to fetch?</p>