title: Refreshing a page as an option in a javascript using ajax
body: <p>The result I want:</p>
  
  <p>Setting a new password. Using modal overlay leanmodal to show result with javascript ajax doing the POST. Before saving the script first checks the new password has not been used the previously ie current pasword, pswdA, pswdB and pswdC. If the pass word matches one of these we want to stop there and return to the last view to enter and repeat password, in my case the same page with the modal overlay refreshed.  The script that follows attempts this but whatever method I use the site navigates to the previous page which contained a solitary old password field, before the new password page where I want the user to be. Here is the script:</p>
  
  <pre><code> // http://www.webstutorial.com/insert-record-into-database-using-ajax-how-to-insert-data-into-database-using-ajax/ajax
  function verifyNewPassword()
      {
          var term_newPassword = $('#newPassword').val(); //Storing the value of textbox into a variable
          var term_mainPw = $('#mainPw').val();
          var term_pswdA = $('#pswdA').val();
          var term_pswdB = $('#pswdB').val();
          var term_pswdC = $('#pswdC').val();
  
          if(term_newPassword === term_mainPw || term_newPassword === term_pswdA || term_newPassword === term_pswdB || term_newPassword === term_pswdC)  //Checking for NULL
              {
                  $('#propspectDiv').html('&lt;h3&gt;Password previously used&lt;h3&gt;');   //Prints the progress text into our Progress DIV
                  $('#newPassword').addClass('error'); 
                  $('#pswdA').addClass('error'); 
                  $('#pswdB').addClass('error');
                  $('#pswdC').addClass('error');                     //Adding the error class to the progress DIV
                  success : function(data){
                  window.setTimeout(function()
                  setTimeout(function()
                  {
                      $(document).attr('location').href='enterNewPassword.php'
                  }, 2000);
                  }
                  return;
              }else{
                  $('#newPassword').removeClass('error');
                  $('#pswdA').removeClass('error');
                  $('#pswdB').removeClass('error');
                  $('#pswdC').removeClass('error');
                  $('#propspectDiv').removeClass('error'); //Removing the error class from the progress DIV
                  $('#propspectDiv').html('Submitting your Request.&lt;div&gt;&lt;img src="images/progress.gif" /&gt;&lt;/div&gt;');//Prints the progress text into our Progress DIV
  
                  $.ajax({
                  type: "POST",
                  url : 'saveNewPW.php', //Declaration of file, in which we will send the data
                  data:{
                          "newPassword" : term_newPassword, //we are passing these values in URL
                          "mainPw" : term_mainPw,
                          "pswdA" : term_pswdA,
                          "pswdB" : term_pswdB,
                          "pswdC" : term_pswdC,
                      },
                  success : function(data){
                  window.setTimeout(function()
                  {
                      $('#propspectDiv').html(''); //Prints the progress text into our Progress DIV
                      $('#data').css("display","block");  //Changes the style of table from display:none to display:block
                      $('#data').html(data);  //Prints the data into the table
                  }, 1000);
  
                  window.setTimeout(function()
                  {
                      $(document).attr('location').href='mainMenu.php'
                  }, 3000);
                  }
              });
          }
      }
  </code></pre>
  
  <p>If I use the browser controls to reload (with a message about resubmitting the form) the page does refresh correctly to the page I want. </p>
  
  <p>I have tried all other suggestions ie window.option.reload(true) and variants but all with the same result.</p>
  
  <p>Ay suggestions appreciated.</p>