我在这个问题上挣扎了几个小时,但没有成功的迹象。我正在尝试实现facebook登录。这是我的代码:
function fblogin() {
FB.login(function(response) {
if (response.authResponse) {
var url = '/me?fields=name,email';
FB.api(url, function(response) {
$('#email_login').val(response.email);
$('#pwd_login').val(response.name);
$('#sess_id').val(response.id);
if($('#evil_username').val()==""){
$('#loginform').submit();
}else{
// doh you are bot
}
});
} else {
// cancelled
}
}, {scope:'email'});
}
但是一旦我点击了facebook的登录按钮,我就会在控制台上看到too much recursion
。为什么会这样呢?我在stackoverflow中读到了很多关于这个问题的问题,但没有找到我的案例的线索。
我这里没有递归,但是是什么导致了递归呢?
有一个呼唤它的
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxx',
channelUrl : '//www.mydomain.de/channel.html',
status : true,
cookie : true,
xfbml : true
});
// Additional init code here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
fblogin();
} else {
// not_logged_in
fblogin();
}
});
};
也可以来自触发fblogin()
的普通LOGIN
按钮。
发布于 2013-07-14 14:17:59
我不知道您的onclick代码在哪里,也看不到调用fblogin()
的操作,我认为问题出在fblogin()
被调用的时候。
function fblogin(event) {
event.stopPropagation();
向每个函数fblogin(event)
调用添加一个事件参数,以便这可以跨浏览器兼容。
当事件发生时,它会遍历父元素,以便它们可以继承事件处理程序,在本例中为function fblogin()
。当您停止传播stopPropagation()
时,就停止了DOM遍历,如果设置了stopPropagation
,则调用该函数的元素不会将处理程序传递给父处理程序。这意味着浏览器将停止遍历所有DOM元素,并减少jquery的递归性。
https://stackoverflow.com/questions/17640040
复制