facebook如何跨域ajax调用?
我期待创建一个 javascript API,其中包含 facebook Javascript API 提供的大部分功能。
FB.api
FB.init
FB.logout
FB.getLoginStatus
FB.login
FB.ui
我可以在远程网站中嵌入脚本标签,并且需要从该页面到我的服务器执行所有 ajax 调用。我正在创建一个架构,需要有人用他/她的优秀想法帮助完成它。
I am looking forward to create a javascript API that contains most of the functions that facebook Javascript API provides.
FB.api
FB.init
FB.logout
FB.getLoginStatus
FB.login
FB.ui
I can just embed script tag in remote website and need to do all the ajax calls from that page to my server. I am creating an architecture and needs someone help in finishing it with his/her excellent ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看 https://github.com /facebook/facebook-js-sdk/blob/deprecated/src/core/xd.js
它们使用 rpc 解决方法(带有中继文件)、Flash 本地连接和 postMessage 的组合,以浏览器支持的为准。
Take a look at https://github.com/facebook/facebook-js-sdk/blob/deprecated/src/core/xd.js
They use a combination of rpc workarounds (with a relay file), Flash Local Connection and postMessage, whichever is supported by the browser.
您还可以查看 跨站 XmlHttpRequest(CORS)< /a>.从你的问题来看,你似乎可以控制你的服务器来响应请求。在这种情况下,您可以调整标头以接收请求并响应跨域请求。
然后,如果您在从嵌入式脚本发出的请求中配置请求标头,您的嵌入式脚本将能够从任何网页与您的服务器通信。
我喜欢这种方法,因为它非常容易实现。但请注意浏览器支持!
You can also take a look at Cross Site XmlHttpRequest(CORS). From your question, it seems that you can control your server that will respond to the requests. In that case, you can tune the headers to receive requests and respond to cross domain requests.
Then, your embedded script will be able to talk to your server from any web page if you configure the request header in the requests that you make from your embedded script.
I like this method as it is extremely easy to implement. Watch out for browser support though!
他们正在使用 JSONP。它被广泛使用,并受到 JQuery 等 JavaScript 框架的支持。
They are using JSONP. It's widely used and is supported by javascript frameworks like JQuery.