jquery LOAD (ajax) 之后的 FB javascript SDK
该脚本适用于
HTML HERE
window.fbAsyncInit = function() {
FB.init({appId: 'XXXXXXXX', status: true, cookie: true, xfbml: true});
console.log('in');
FB.getLoginStatus(function(response) {
console.log(response);
if (response.session) {
// logged in and connected user, someone you know
code here
}
} else {
// no user session available, someone you dont know
code here
}
});
};
HTML HERE
我最近想要 ajaxify 网站的同步请求, 当我创建一个 XMLHttpRequest 将其附加到页面上(使用 JQuery 的 ajax GET 请求的加载简写)时,javascript 方法 FB.getLoginStatus 不会被执行。
让我分享控制台结果:
synchronous: in , response (object) asynchronous: in
有人可以帮忙吗?
he script works fine for synchronous requests
HTML HERE
window.fbAsyncInit = function() {
FB.init({appId: 'XXXXXXXX', status: true, cookie: true, xfbml: true});
console.log('in');
FB.getLoginStatus(function(response) {
console.log(response);
if (response.session) {
// logged in and connected user, someone you know
code here
}
} else {
// no user session available, someone you dont know
code here
}
});
};
HTML HERE
I recently wanted to ajaxify the site,
when I make an XMLHttpRequest to append it on the page (using JQuery's load shorthand for ajax GET req.) the javascript method FB.getLoginStatus does not get executed.
let me share the console results:
synchronous: in , response (object) asynchronous: in
can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,就像 facebook 制作库的方式一样,你不能使用 FB.init({});所以我们必须找到一种方法来摧毁它并再次创造它!使用内置函数可能有更简单的方法,但这是一种肯定有效的方法。我已经这样做了,删除了整个 FB 对象,当我找到最佳解决方案时,我会回复!
更新
好的,就是这样,找到了解析新元素的内置函数
... 解决方案:
//您希望使用包含 xfbml 的最少生成的父元素以获得最佳性能,在 jQuery 加载的情况下,它将是这样使用的元素:
I'm having the same problem the way facebook made the library you can't use FB.init({}); again so we have to find a way to destroy it and create it again! There might be easier way using built in functions but this is a way that will definitely work. I already did this buy removing the entire FB object, I'll post back when I find the best solution!
UPDATE
Ok here it is, found the built in function to parse for new elements
... SOLUTION:
//you want to use the least generation of parent elements containing the xfbml for best performance, in case of jQuery load it will be the element being used like this: