title: jquery ajax request succeeds even when page is redirected before request
body: <p>While trying to figure out how to redirect to a new page after a successful post request, I was trying to understand how ajax works and tried to break the request by trying the code below.</p>
  <pre><code>window.location.replace(new_url) // redirect BEFORE post request
  // jquery post request
  $.ajax({
      type: &quot;POST&quot;,
      url: url,
      data: data,
      contentType: &quot;application/json&quot;,
  })
  </code></pre>
  <p>I redirected the page <strong>before</strong> I made the post request with jquery. Surprisingly, the post request was successful and the data were saved in my database (not sure if relevant, but I posted/sent very little data while testing my code).</p>
  <p>I thought the correct way is to make a post request, ensure the request is completed successfully, <strong>then</strong> redirect the page. Here, I redirected before I even made a request and the data were still sent to my database. Can someone explain why/how did that happen? Thanks!</p>