title: Ajax redirect to another page on success
body: <p>I want to make registration new user with HTTP POST method using Ajax and Spring as backend. Then I write a function to send JSON to controller and it's working well (tested, I can receive form values and persist data in DB). The problem is that, I can't redirect after processing to another page eg. 'registerSuccess.jsp'. All the time it's redirecting me to the 'register' page, appending all form values as 'GET' params. </p>
  
  <p>Ajax function:</p>
  
  <pre><code>       $('.ui.form').on('submit', function(){
              $.ajax({
                  url: '/PhotoAlbum/user/register/',
                  type: "post",
                  data: formToJSON(),
                  dataType : "json",
                  contentType: 'application/json; charset=utf-8',
                  async: false,
                  success : function(data){
                      console.log("Inside Success");
                      console.log(data);
                      window.location.href = "/PhotoAlbum/user/regsuccess.jsp";
                  },
                  error : function(xhr, status){
                      console.log(status);
                  }
              })
          })
      })
  ;
        function formToJSON() {
            return JSON.stringify({
                "firstName": $('.ui.form').form('get value', 'firstName'),
                "lastName": $('.ui.form').form('get value', 'lastName'),
                "email": $('.ui.form').form('get value', 'email'),
                "password": $('.ui.form').form('get value', 'password'),
                "matchingPassword": $('.ui.form').form('get value', 'matchingPassword')
            })
        }
  </code></pre>
  
  <p>@Controller method:</p>
  
  <pre><code>@RequestMapping(value = "register/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
          consumes = MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody GenericResponse registerUserAccount(@RequestBody UserDTO user, HttpServletRequest request)
  {
      LOGGER.debug("Registration of account: ", user);
  
      User user1 = new User();
  
      user1.setFirstName(user.getFirstName());
      user1.setLastName(user.getLastName());
      user1.setEmail(user.getEmail());
      user1.setPassword(user.getPassword());
  
      userRepository.save(user1);    
  
      return new GenericResponse("success");
  }
  </code></pre>
  
  <p>Console logs:</p>
  
  <pre><code>Inside Success
  (index):134 
  Object {message: "success", error: null}
  
  Navigated to http://localhost:8080/PhotoAlbum/user/register/?firstName=John&amp;lastName=…email=john%40gmail.com&amp;password=SecretPass&amp;matchingPassword=SecretPass
  </code></pre>
  
  <p>Thank's for help.</p>