Facebook's Unique Ajax Support

John Musser
Aug. 08 2007, 12:36AM EDT

The Facebook Platform is quietly moving beyond its initial, somewhat limited "mock ajax" roots for platform UI development. They've quietly released a beta version of FBJS, Facebook JavaScript. FBJS is an interesting twist on how to allow richer intereactivity without requiring developers to resort to using iframes (which are inherently more isolated from the full Facebook user experience). Some useful notes from their wiki:

FBJS is Facebook's solution for developers who want to use Javascript in their Facebook applications.

Most providers who allow developers to embed Javascript within their domain force developers to use iframes to sandbox their code. Facebook has taken a different approach to this problem. Javascript that you give us will be parsed, and any identifiers (function and variable names) will be prepended with your application id. For example, the following code block:

function foo(bar) {
  var obj = {property: bar};
  return obj.property;
}

will become:

function a12345_foo(a12345_bar) {
  var a12345_obj = {property: a12345_bar};
  return a12345_obj.property;
}

This creates a virtual scope for every application that runs within Facebook's page. From there we expose certain functionality through a collection of Javascript objects which allow you to modify your content on Facebook. Our objects are made to mimic the functionality of Javascript as closely as possible, but it may take some getting used to for people who are already adept with Javascript.

The Javascript syntax you've come to know and love (or hate) is exactly the same. You can create objects, use anonymous functions, create timeouts and almost any other thing you can think of...

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.

The pace of innovation at Facebook continues to raise the ante for all competing social network platforms who have yet to release even their first APIs. [via]

John Musser

Comments

Comments(1)

User HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

I would like to thnkx for the efforts you have put in writing this site. I'm hoping the same high-grade website post from you in the upcoming as well. Actually your creative writing skills has encouraged me to get my own web site now. Really the blogging is spreading its wings rapidly. Your write up is a great example of it.