Tuesday, September 18th, 2007p>Marcel Laverdet of Facebook blogged about the release of FBJS 1.0:
We hope that FBJS enables you to build deeply integrated Facebook Platform applications in new and interesting ways.
With respect to Ajax, they give you an object to work with that sits on top of XHR, and is proxied by Facebook servers:
FBJS supplies a very powerful AJAX object for developers. Facebook will proxy all AJAX requests and optionally run useful post-processing on the data returned, such as JSON, or FBML parsing. To use it, just instantiate a new Ajax class. It supports the following properties:
- An event handler which fires when an AJAX call returns. Depending on .responseType, data will either be an object, a raw string, or an FBML string.
- 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 one 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.
Here’s an example showing most of the functionality of Ajax:
It is interesting to see more and more platforms wanting to open up and give users more abilities, but keeping the balance wrt security, privacy, and general abuse.
There are also rumors of new functionality to come, such as a data storage API.
Posted by Dion Almaer at 12:20 pm