title: POST request Fetch API prevent redirect
body: <p>So i want to make a pure html and javascript form and submit it to server.</p>
  
  <p>Here is my html form code:</p>
  
  <pre><code>&lt;form id="email-signup" action="http://www.server.com" method="post"&gt;
      &lt;input id="firstname-input" type="hidden" name="firstname" value=""&gt;
      &lt;input type="text" name="email" placeholder="Input Email"&gt;
      &lt;input type="hidden" name="campaign[id]" value="1"&gt;
      &lt;input type="hidden" name="campaign[name]" value="Text Campaign"&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is my javascript code:</p>
  
  <pre><code>var element = document.getElementById("email-signup");
  element.addEventListener("submit", function(event) {
    event.preventDefault()
    fetch("http://www.endpoint.api", {
      method: "POST",
      body: new FormData(document.getElementById('email-signup'))
    })
  })
    .then(() =&gt; {
    alert('Selamat email anda sudah terdaftar!')
  })
  </code></pre>
  
  <p>The problem is, whenever i submit an email to that form it redirects me to a new page with a response of success. I want to prevent that to happen and instead it will pop up an alert that tells me the email submission is succeeded.</p>