FB.api 调用后不需要的页面重新加载
Unwanted page reload after FB.api call
我在使用带有coffeescript的Facebook api时遇到问题。每次我执行FB.getLoginStatus
并且状态为"connected"
,我都会调用FB.api("/me", (data)->console.log(data))
页面自动重新加载,而无需我要求。
另一个问题是,如果在console.log
调用后放置断点并观察数据的价值,则会从Facebook获得错误。
想知道我是否这样做正常,以及总体上为什么要重新加载页面。
以下是该页面的咖啡脚本代码:
window.fbAsyncInit = ->
FB.init
appId: document.getElementById("fb-root").getAttribute("data-app-id")
channelUrl: document.getElementById("fb-root").getAttribute("data-channel-url")
status: true,
cookie: true,
xfbml: true
FB.Event.subscribe('auth.login', (response) ->
window.location = window.location
)
FB.Canvas.setAutoGrow()
FB.getLoginStatus((data) ->
console.log(data)
if (data.status == "connected")
uid = data.authResponse.userID
accessToken = data.authResponse.accessToken;
FB.api("/me", (data) ->
console.log(data) // Here is the last call before the reload
)
else if (data.status == "not_authorized")
console.log("Je suis log a facebook")
$("#FBConnect").on("click", (e) ->
FB.login( (response) ->
if response.authResponse
console.log('Welcome! Fetching your information.... ');
FB.api('/me', (response) ->
console.log('Good to see you, ' + response.name + '.');
)
else
console.log('User cancelled login or did not fully authorize.');
)
)
# the user is logged in to Facebook,
# but has not authenticated your app
else
console.log("Je ne suis pas connecte a facebook")
# the user isn't logged in to Facebook.
)
PageScript = document.getElementsByTagName("script")[0]
return if document.getElementById("FBScript")
FBScript = document.createElement("script")
FBScript.id = "FBScript"
FBScript.async = true
FBScript.src = "//connect.facebook.net/en_US/all.js"
PageScript.parentNode.insertBefore(FBScript, PageScript)
页面重新加载可能是由于代码中的以下行:
FB.Event.subscribe('auth.login', (response) ->
window.location = window.location
)
当auth
状态从 unknown
更改为 connected
时,将触发auth.login
,因此当您连接时,代码将执行,当您在该函数中重新加载页面时,页面将重新加载。删除行::window.location = window.location
应该可以解决它。
相关文章:
- 创建新数据和加载现有数据需要单独的视图吗
- 钛 - HTTPClient:打开新的控制器加载
- 保持 JavaScript 在浏览器控制台中运行,即使在新的页面加载之后也是如此
- 路由到新页面时加载不起作用
- 如何在新窗口完成加载后执行某些内容
- 使用新标题重新加载 html 页面
- Primefaces在打开新页面时加载数据消息
- Wordpress音频播放器和平滑状态.在新页面重新加载播放器时调用什么回调函数
- 用新数据重新加载renderer3d
- 文本不被渲染后,新的页面加载- JQuery移动
- 需要在新标签中加载pdf/doc文件,而不是下载,只是想在浏览器中阅读
- 用新参数重新加载页面
- Js和CSS不检测新页面何时加载
- 在新页面上加载一个flash视频,它在上一页上的位置
- 在新窗口中加载代码编写器视图
- 在控制台中使用新脚本重新加载页面
- 如何在加载新页面后加载AJAX数据
- 如何使用jQuery在新窗口中加载页面,然后关闭它们
- Jquery没有看到新的HTML加载到对话框中
- 无法用新值重新加载JGrid