I do not know if my title was perhaps a little misleading. But here's what I really need help with.
I'm making a get on this url:
$.get("/fb/login/"+fbEmail, function(data){
console.log(data);
});
This is my routes:
GET /fb/login/:email presentation.controllers.Auth.authenticateSocialNetwork(email:String)
And here's my action:
def authenticateSocialNetwork(email:String) = Action {
if(!editorRepo.getEditorByEmail(email).isEmpty){
Redirect(routes.Profile.editorProfile).withSession(Security.username -> email)
} else {
Redirect(routes.Profile.initiatorProfile).withSession(Security.username -> email)
}
}
My expectation from this is that my action gets called and fires of what's inside it. In other words, Redirecting.
But what actually happens, which is not so illogical, is that my $.get call gets a response with my redirect's.
How do I actually call my action-method, without sending a response to javascript?
Here's my function in javascript, posting this snippet for it to be more clear in our discussion in the comments above.
function addClickToLoginButtons(){
$("#loginWithFb").click(function(){
FB.login(function(response){
if(response.authResponse){
FB.api('/me', function(response){
var fbEmail = response.email;
$.get("/fb/isRegisteredAtNetwork/"+fbEmail+"/facebook", function(data){
if(data == "true"){
if(confirm("Do you want to log with facebook-account "+fbEmail+"?")){
$.get("/fb/login/"+fbEmail, function(data){ *//HERE'S WHERE I WOULD WANT TO CALL MY METHOD IN SCALA*
console.log(data);
});
} else {
console.log("try again with a different facebook-account");
} //end confirm else
} else {
console.log("Logged in not in database");
}//end get else
});
});
} else {
console.log("permission not granted");
} // end authResponse else
}, {scope: 'email'});
});
}
authenticateSocialNetwork, I don't really see how an http request would prevent you from using your trait variables. Do you get any errors when using a http request with this? If so, what are the errors?authenticateSocialNetworkgets executed it sends a response to ajax. This response includes my redirected page, but it doesnt actually redirect. This is my problem. I dont want to send a respons, I want to execute whats inside myauthenticateSocialNetwork. When you say http call, do you mean from the javascript file or in theauthenticateSocialNetworkmethod? If I redirect from my javascript file I wont be able to use my trait? I might be a little confused :)<a href="http://example.com/fb/login/[email protected]">Click here</a>Once this button clicked, the actionauthenticateSocialNetworkis called and is passed the appropriate email, this will then redirect your user... In ajax, I don't think that's actually possible, since it's gonna wait for the response from the server and in your case it's a redirect response.