title: Spring MVC 3, forwarding not working when using Ajax
body: <p>I have very interesting problem. I am making log in page for my web app and I am sending login request via AJAX. If success I want to forward user to another page. </p>
  
  <p>It seems that his is what happens. I send Ajax request, controller forwards me to need view (I see log in debug mode) but I stay on the same page, since I assume the page is waiting for AJAX response and for that reason forwarding does not happen. </p>
  
  <p>I think this is also wrong way to approach this but since I am new to this don't know better. How can I log in and and forward user to next page.</p>
  
  <p>Thank you.</p>
  
  <p>Here is my code:</p>
  
  <p>JS Code:</p>
  
  <pre><code>    Page.authenticate = function() {
          $.ajax({
                url: "/login/authenticate/" + $('#username').val() + "/" + $('#password').val(),
                type: "GET",
                success: function(poi){
                   // alert("nesto");
                }
             });
  
          return true;
      }
  </code></pre>
  
  <p>Controller Class:</p>
  
  <pre><code>@Controller
  public class LoginPageController {
  
  private Logger logger = Logger.getLogger(this.getClass());
  
  @Autowired
  private UserManagement userManagement; 
  
  @RequestMapping(value="/login/authenticate/{username}/{password}", method=RequestMethod.GET)
  public String authenticate(@PathVariable("username") String userName, @PathVariable("password") String password, Model model) {
  
  if (userManagement.authenticateUser(userName, password)) {
          String forward = "forward:/login/success";
          return forward;
      } else {
          model.addAttribute("errorMessage", "Invalid Username/Password, please try again!");
          return "/";
      }
  
  }
  
  }
  </code></pre>