Monday, August 6th, 2007

Richer Ajax support for Facebook

Category: Social Networks

Mock Ajax? Huh. That is what I thought when I first read the documentation on building Facebook applications. It was a little sad to see that your choice was either to use the “mock ajax” calls, or to jump into iframe land and do everything on your server, thus not interacting with the Facebook shell.

Well, now JavaScript is going to be a first class citizen with FBJS:

FBJS is Facebook’s solution for developers who want to use Javascript in their Facebook applications. We built FBJS to empower developers with all the functionality they need, and to protect our user’s privacy at the same.

And an Ajax object is available:

FBJS supplies a very powerful AJAX object for developers. It supports retrieving JSON, FBML, or raw text from remote servers. To use it, just instantiate a new Ajax class.

An event handler which fires when an AJAX call returns
An event handler which fires when an error occurs during an AJAX call
If you set this to true the AJAX call will require the user to be logged into your application before the AJAX call will go through. The AJAX call will then be made with the regular fb_sig parameters containing the user’s identity. If they refuse to login, the AJAX call will fail.
This can be on of Ajax.RAW, Ajax.JSON, or Ajax.FBML.

The response from your server will be returned to your callback in its original form.
The response from your server will be parsed as a JSON object and returned to your callback in the form of an object. Properties of your JSON object which are prefixed with “fbml_” will be parsed as individual FBML strings and returned as FBML blocks. These blocks can used on a DOM object with the setInnerFBML method.
The response from your server will be parsed as FBML and returned as an FBML block. This block can used on a DOM object with the setInnerFBML method.

And one method:

post(url, query) 
Start an AJAX post. url must be a remote address, and query can be either a string or an object which will be automatically converted to a string.

Hopefully this will mean richer Ajax apps on the Facebook platform.

Posted by Dion Almaer at 1:14 am

3.6 rating from 45 votes


Comments feed TrackBack URI

I was curious how they would handle Javascript. From what I saw the implementation seems to be fairly nicely done. Security at this point is hard to say. You can bet that someone will find a way to screw with more than they are allowed.

Imagine a viral application similar to the first mySpace virus that added some dude to your friends list. Javascript is definitely a nice thing to have, but it is also a security nightmare, so I am very interested to see the reaction when the exploits arrive.

Comment by Philip Plante — August 6, 2007

Hopefully this will mean richer Ajax apps on the Facebook platform.

And hopefully it will mean someone will build a useful application on facebook. I don’t need 10 applications to update my mood!

Comment by justin — August 6, 2007

The abstraction is so clean and useful. I hope someone will write a converter or application layer that allows Facebook apps to run on the desktop without needing a browser or Facebook.

Comment by Jordan — August 6, 2007

I really like this!

Comment by Hugh Jarse — August 6, 2007

@Jordan… I wonder if the FB implementations forthcoming via the ParaKey purchase will address this? (I’m guessing this is going to be very cool, can’t wait to see what Joe Hewitt has been working on) ……..but still there is the possibility of using Google Gears (Dojo has an abstraction) or Adobe AIR for your apps to accomplish this, is there not? || @Philip: “…and most of all Samy is my hero” :)

Comment by Mark Holton — August 6, 2007

Was anyone actually able to use the new Ajax object and to make it work?

I tested it and tried running the samples that they give in the documentation (and other tests) – none of them seem to work, not in the
FBML Test Console ( or in a normal Facebook application.

Comment by Yuval — August 10, 2007

Leave a comment

You must be logged in to post a comment.