0

I am trying to redirect to another route, and even tho I get the html response, and in the inspect element I see that the page sends a get request to the next route, it does not load. Why ?

My routes:

GET    /                            controllers.HomeController.index
GET    /hello                       controllers.HomeController.hello
GET    /home                        controllers.HomeController.home
GET    /login                       controllers.HomeController.login
GET    /register                    controllers.HomeController.signup
GET    /auth/login                  controllers.AuthController.login(username: String, password: String)

My jquery:

function login () {
             var username = $('#username').val();
             var password = $('#password').val();
             $.get("/auth/login", {username: username, password: password});
         }

My controller for the /auth/login route:

 @Inject
private AuthService authService;

public Result login(String username, String password) {
    // post request
    boolean login = authService.login(username, password);

    if (login)
        return redirect(controllers.routes.HomeController.hello());

    else
        return redirect(controllers.routes.HomeController.signup());
}

My authService:

 public class AuthService extends RestService {

public boolean login(String username, String password) {


    WSRequest request = createRequest("/users/login")
            .setQueryParameter("username", username)
            .setQueryParameter("password", password);

    JsonNode jsonNode = get(request);

    boolean b = jsonNode.asBoolean();

    return b;
}


}

My register and hello methods in HomeController:

public Result hello() { return ok(views.html.hello.render()); }

public Result signup() { return ok(views.html.signup.render()); }

I want that the page loads. I do not know why it does not load in the first place even tho I get the html response on /auth/login route in the inspect element it just does not want to completely redirect it. Really weird.

Thelouras
  • 852
  • 1
  • 10
  • 30
  • You may try to share whole project GitHub repo. Having all your code may help to understand the issue. – YuriR Feb 17 '19 at 20:07
  • Its not play framework, its your ajax call that cause that behavior. See for example https://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call. – Tijkijiki Feb 18 '19 at 14:08

0 Answers0