0

我有我想在函数中的按钮单击事件上执行的 php 代码。我以各种方式尝试但没有运气。这很容易,但我是新手,所以做不到。

<?php
session_start();
$appId = '----'; 
$appSecret = '----'; // Facebook App Secret
$return_url = 'dev01.dev/FB/facebook-php-sdk/examples/';  //path to script folder
  ?>
<!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()
 {

    alert("hi");
   }

function LodingAnimate() //Show loading Image
{
    $("#LoginButton").hide(); 
      AjaxResponse();    
}
 </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();                    
         } //if
             }); //---
          } 
       <div id="results"> 
          </div>
       </script>
</body>
</html>

如果可能的话,我想在 ajaxResponse 函数中执行。我的代码是:

if (!class_exists('FacebookApiException')) {
    require_once('facebook.php' );
    }
        $facebook = new Facebook(array(
        'appId' => $appId,
        'secret' => $appSecret,
    ));
    $fbuser = $facebook->getUser();
    if ($fbuser) 
    {
            try {
             $user_interest = $facebook->api('/me/movies');echo '<pre>';
            foreach ($user_interest['data'] as $var)
        {
             $ID=$var['id'];
             $Name=$var['name'];
             echo '<br/>';
             print_r($Name); echo '<br/>';
             print_r($ID);
        }
        echo '</pre>';
    }
    catch (FacebookApiException $e) {
        echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
        $user = null;
    }
    }
4

0 回答 0