Posted By

nalmeida on 06/02/10


Tagged

facebook fbml


Versions (?)

Facebook Ajax


 / Published in: HTML
 

URL: http://wiki.developers.facebook.com/index.php/FBJS/Examples/Ajax

  1. These links demonstrate the Ajax object:<br />
  2. <a href="#" onclick="do_ajax(Ajax.JSON); return false;">JSON</a><br />
  3. <a href="#" onclick="do_ajax(Ajax.RAW); return false;">RAW</a><br />
  4. <a href="#" onclick="do_ajax(Ajax.FBML); return false;">FBML</a><br />
  5. <label><input type="checkbox" id="requirelogin" checked="checked" /><span>Require Login?</span></label><br />
  6. <div><span id="ajax1"></span><span id="ajax2"></span></div>
  7.  
  8. <script><!--
  9. function do_ajax(type) {
  10. var ajax = new Ajax();
  11. ajax.responseType = type;
  12. switch (type) {
  13. case Ajax.JSON:
  14. ajax.ondone = function(data) {
  15. document.getElementById('ajax1').setTextValue(data.message + ' The current time is: ' + data.time + '. ');
  16. document.getElementById('ajax2').setInnerFBML(data.fbml_test);
  17. }
  18. break;
  19.  
  20. case Ajax.FBML:
  21. ajax.ondone = function(data) {
  22. document.getElementById('ajax1').setInnerFBML(data);
  23. document.getElementById('ajax2').setTextValue('');
  24. }
  25. break;
  26.  
  27. case Ajax.RAW:
  28. ajax.ondone = function(data) {
  29. document.getElementById('ajax1').setTextValue(data);
  30. document.getElementById('ajax2').setTextValue('');
  31. }
  32. break;
  33. }
  34. ajax.requireLogin = document.getElementById('requirelogin').getChecked();
  35. ajax.post('http://example.com/testajax.php?t='+type);
  36. }
  37. //--></script>

Report this snippet  

You need to login to post a comment.