Mock AJAX
From Facebook Developer Wiki
FBML supports mock AJAX functionality. On any element, you specify the attributes clickrewriteid, clickrewriteform, and clickrewriteurl. When the user clicks on that element, the contents of the form specified with clickrewriteform gets POSTed to Facebook's servers and then relayed to the URL specified with clickrewriteurl. This URL should return FBML, not the HTML that a normal Web server would. The Facebook server then renders this FBML into HTML and replaces the innerHTML of the DOM element you specified with clickrewriteid.
It may sound complicated, but this way Facebook Platform retains control over requests, and gets to render any FBML specific code.
It should be noted that a presence of a form is required, so for any trivial requests or those with GET arguments, set up a dummy form, like the following.
Which roughly translates into:
And the result is rendered into an element specified by clickrewriteid, in this case a DIV with an ID set to "your_content".
--589457036 08:38, 28 June 2007 (PDT)
This may have been mentioned elsewhere, but with the PHP library (PHP5 specifically), using the require_frame() function could give you problems with the mock AJAX.
--732135601 20:54 14 March 2008 (GMT+2) Note mock AJAX doesn't work with the apps.facebook url. you need to point it directly to your callback url...seems kinda obvious in hindsite.
--Tony 12:17, 19 June 2007 (PDT)
32700928 15:24, 30 July 2007 (PDT)
Mock AJAX seems to require that you enter a valid DIV ID for clickrewriteid. This is frustrating if you don't want to display any results, but can be worked around by adding <style="display: none;" to the resulting DIV.
I'm sure you guys are working on this, but a loading indicator would make my day.
[edit] Misc Examples
[edit] Basic Functionality
A live demonstration can be found here. (Facebook login required, app login not required) NB this does not work at present.
Mock AJAX not working? Check your application settings and make sure "Canvas Page URL" is set to "Use FBML".
[edit] Loading Indicator
I don't think that a default loading indicator will be introduced, since it's more of a design element than API functionality. That being said, here's how to implement your own loading indicator for mock AJAX:
Combine clicktoshow of DynamicFBML/Visibility with clickrewrite* options on the same element. Place a hidden loading indicator (spinner.gif for example) inside the clickrewriteid element. Make sure to generate a new hidden indicator in the clickrewriteurl for repeat calls.
At the same time as the mock AJAX request is made, the loading indicator becomes visible. We cannot monitor for onComplete status to hide the indicator, but since it's nested in the element that is being replaced, the indicator disappears when the request is loaded.
http://your_server/ajax.php should serve <img src="http://your_server/spinner.gif" id="spinner" style="display:none;"/> so that the hidden indicator element once again becomes accessible for the following calls.
--Tony 09:12, 25 June 2007 (PDT)
That will not work if the request fails, you will be stuck with a spinning GIF and no explanation to the user why it is like that.
--593205213 03:02, 18 December 2007 (PST) You are correct but I have many times seen Gmail get stuck and just leave the "loading" text showing. If its good enough for Google, its good enough for me!
What about using onerror to remove the spinner and optionally pop up a dialog with "Oops! Something went wrong"? --1106463354 03:19, 25 March 2009 (PDT)
--516237517 12:44, 19 March 2008 (PDT) What does your function need to return? I try to echo, return, or load an html page consisting of fbml and nothing shows up in the div I set.
