关于下面的代码,是什么原因导致我通过completeLogin()函数成功重定向的页面不断重新加载自身?
更多背景 -
用户可以通过Facebook登录我的应用程序。在用户按下按钮以启动该功能并通过Facebook成功进行身份验证后,我便希望启动登录的页面以及从Facebook接收成功登录信息的页面重定向到另一个用户,然后用户可以完成我的申请的注册过程。正如我上面提到的,页面确实被重定向到我需要它的位置。
页面继续重新加载,因为我知道有些东西正在被立即调用,我需要知道如何阻止它。
非常感谢, CM
<script>
// Called with the results from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object returns with a status field that lets the
// app know the current login status of the person.
if (response.status === 'connected') {
// User is logged into your app and Facebook.
console.log("You are connected.");
completeLogin();
console.log("completeLogin called")
testAPI();
} else {
// The person is not logged into your app or we are unable to tell.
document.getElementById('status').innerHTML = 'Please log ' +
' into this app.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
function completeLogin()
{ location.href = '@Url.Action("ExternalLoginConfirmation", "Account")'; }
window.fbAsyncInit = function() {
FB.init({
appId: '1614609378567893',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.8' // use graph api version 2.8
});
// FB.getLoginStatus() gets the state of the
// person visiting this page and can return one of three states to
// the callback provided:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// handles these three cases in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Running a simple test of the Graph API after login is
// successful.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
答案 0 :(得分:0)
以下代码导致页面重新加载:
location.href = '@Url.Action("ExternalLoginConfirmation", "Account")';
location
是窗口上的变量,它始终在范围内。更改此值会触发用户代理转到您将href
属性设置为的地址。这类似于window.location
重定向
window.location = "http://www.google.com";
在这些情况下,只需开始删除代码段/代码行,直到它停止不可预测的行为为止。