mal*_*ing 2 ajax action scala ajax-request playframework-2.0
我不知道我的头衔是否有点误导.但这是我真正需要帮助的.
我正在搞这个网址:
$.get("/fb/login/"+fbEmail, function(data){
console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
GET /fb/login/:email presentation.controllers.Auth.authenticateSocialNetwork(email:String)
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
我对此的期望是我的行动被召唤并触发其中的内容.换句话说,重定向.
但实际发生的事情,不是那么不合逻辑,就是我的$ .get调用得到了我的重定向响应.
如何在不发送对javascript的响应的情况下实际调用我的action-method?
这是我在javascript中的功能,在上面的评论中我们的讨论中更清楚地发布了这个片段.
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'});
});
}
Run Code Online (Sandbox Code Playgroud)
在您的操作中,不是返回Redirect,而是返回Ok(urlToBeRedirectedTo).withSession(...).一旦在javascript代码中收到此响应,请执行您的操作然后调用window.location = urlToBeRedirectedTo;.
这会将电子邮件添加到会话中,并将重定向到所需的URL.
| 归档时间: |
|
| 查看次数: |
1124 次 |
| 最近记录: |