dealing with ajax on FBConnect
problem :
need to store users information by ajax call while on connect . but face problems using fbjs ajax calls using on connect .some times face the problem to send ajax request in the forum also get related type of problems . like:
http://forum.developers.facebook.com/viewtopic.php?id=28153
http://forum.developers.facebook.com/search.php?search_id=92171720
let’s see a quick solution by a common example.
solution:
here we look at the after connect get user profile picture and name by connect.
we create a script connect.php and include the config file .connect.php
<?php
/*
* include config file
*/
?>
<div id="user"> </div>
<fb:login-button onlogin="update_user_box();"></fb:login-button>
<script type="text/javascript">FB.init("key", "xd_receiver.php"); </script><span style="display: block; padding-left: 6em;"><span>
now it’s look like that:

here in the connect button add onlogin function update_user_box().while click on connect then this function will call and update user by profile picture and name in the user id div.
in that update_user_box() function we will get the profile picture and name by calling ajax. So later on we can do anything by ajax.to call the ajax we will do it by jquery. Here I cannot do it by the fbjs ajax method. For that reason I add jquery and other scripts.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
now update update_user_box
<script type="text/javascript">
function update_user_box()
{
Var url = “http://www.t...com.display.php”; // ajax url which is here display.php
$.ajax({
type: "POST",
url:url,
data: "save=yes",
success: function(msg){
var user_box = document.getElementById("user");
user_box.innerHTML =msg;
}
});
}
now create the display.php Which call by ajax.
In the display php also include config file which include facebook client library
here is code
<?php
define(MAIN_PATH, realpath('.'));
include_once MAIN_PATH.'/init.php';
$fb_uid = facebook_client()->get_loggedin_user();
echo '<span> <fb:profile-pic uid='.$fb_uid.' facebook-logo=true></fb:profile-pic> Welcome, <fb:name uid='.$fb_uid.' useyou=false></fb:name>. You are signed in with your Facebook account.</span>';</span></span></span></span>
?>
<span style="display: block; padding-left: 6em;"><span>
this display.php returns the user profile picture and name. and it’s look like that.

that’s it
3 Responses to “dealing with ajax on FBConnect”
Leave a Reply



























pedley on February 11th, 2009
Hi thanks for the help, you may want to check your code since the php script won’t work if copied as is I had to edit it to make it work, but I did get the stuff working that I wanted which was mainly the AJAX.
Vytoldas on August 10th, 2009
But why facebook connect button do not disappear after login ?
harald on January 13th, 2010
@pedley: what did you have to edit?