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.