我正在从 facebook 中检索可以在控制台上显示但未能在 html 页面上显示的数据。
我试过:
$("#mydiv").text(data);
或者
$("#mydiv").append(data);
[object Object]
在浏览器上显示。
我的代码是:
<?php
session_start();
$appId = 'APPID';
$appSecret = 'APPSECRET'; // Facebook App Secret
$return_url = 'dev01.dev/FB/facebook-php-sdk/examples/'; //path to script folder
//$fbPermissions = 'publish_stream,email'; //more permissions : https://developers.facebook.com/docs/authentication/permissions/
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en-gb" lang="en-gb" ><head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<title>JS/Ajax Facebook Connect</title>
<script>
function AjaxResponse()
{
var myData = 'connect=1';
$.ajax({
type: "POST",
url: "process_facebook.php",
data: myData
}).done(function(result) {
$("#fb-root").html(result);
});
}
function LodingAnimate() //Show loading Image
{
$("#LoginButton").hide(); //hide login button once user authorize the application
}
</script></head><body>
<?php
if(!isset($_SESSION['logged_in']))
{
?>
<div id="results"> </div>
<div class="results1"> </div>
<div id="LoginButton">
<button type="button" onclick="CallAfterLogin()" ?>Click Me!</button>
</div>
<?php
}
?>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $appId; ?>',
cookie: true,
xfbml: true,
channelUrl: '<?php echo $return_url; ?>channel.php',
oauth: true});};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);}());
function CallAfterLogin(){
FB.login(function(response) { //---
if (response.status === "connected")
{
LodingAnimate(); //Animate login
// FB.api('/me?fields=movies,email', function(data) { //--
FB.api('/me', function(data) { //--
$("#results").text(data);
console.log(data);
if(data.email == null)
{
alert("You must allow us to access your email id!");
ResetAnimate();
}else{
AjaxResponse();
}
}); //--
} //if
}); //---
} //main function
<div id="results"> </div>
</script>
</body>
</html>