title: Success function in my ajax request not executing
body: <p><strong>First problem:</strong> Page would redirect, but my AJAX request was ignored.</p>
  
  <p><strong>New problem:</strong> AJAX request posts the data, but page will not redirect.</p>
  
  <p>My goal is to send the AJAX request, confirm that the data have been sent and stored on the server, and then redirect to a new page once that has completed.</p>
  
  <p>I have tried using a success function within my AJAX request to achieve this. If I put the page redirect OUTSIDE the AJAX request, it redirects the page but the AJAX response is halted. If I put the page redirect INSIDE the AJAX request, the data post but the page does not redirect.</p>
  
  <pre><code>    $.ajax({
          type: "POST",
          url: "saveData.php",
          dataType: "text/plain",
          ContentType: "charset=utf-8",
          data: {"data": surveydata, "userID": userID, "trialType": trialType},
          success: function (data) {
              if (!data.error) {
                  console.log("success");
                  window.location.replace("anotherpage.html");
              } else {
                  console.log("error");
          }}})
  </code></pre>
  
  <p>I have also tried it this way:</p>
  
  <pre><code>    $.ajax({
          type: "POST",
          url: "saveData.php",
          dataType: "text/plain",
          ContentType: "charset=utf-8",
          data: {"data": surveydata, "userID": userID, "trialType": trialType},
          success: function (data) {
                  console.log("success");
                  window.location.replace("anotherpage.html");
          }}})
  </code></pre>
  
  <p>I want to achieve both a successful page redirect and the posting of the data. I am unaware of how to force the page redirect to wait until the AJAX request has succeeded. I have read through the other questions on this topic and tried several methods, but none have worked so far.</p>