FB Series: AJAX & Facebook debugging

The php facebook client has a nice setting to track the different http calls between your app and facebook. You can enable this with:

$GLOBALS['facebook_config']['debug'] = true;

This will actually insert some script code to the header of every page served, in order to render the tracking code, if there is something to render:

<script type="text/javascript">
var types = ['params', 'xml', 'php', 'sxml'];
function getStyle(elem, style) {
  if (elem.getStyle) {
    return elem.getStyle(style);
  } else {
    return elem.style[style];
  }
}
function setStyle(elem, style, value) {
  if (elem.setStyle) {
    elem.setStyle(style, value);
  } else {
    elem.style[style] = value;
  }
}
function toggleDisplay(id, type) {
  for (var i = 0; i < types.length; i++) {
    var t = types[i];
    var pre = document.getElementById(t + id);
    if (pre) {
      if (t != type || getStyle(pre, 'display') == 'block') {
        setStyle(pre, 'display', 'none');
      } else {
        setStyle(pre, 'display', 'block');
      }
    }
  }
  return false;
}
</script>

The catch is that the script code is always inserted, even if there were no facebook api calls involved. So the script code renders at the top for every page, also when its a JSON AJAX response. This means of course that the JSON will not be parsed on the browse – not good.

I now use other tools to track what requests are being sent back and forth instead between my application and facebook.

This entry was posted in debugging, facebook and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

2 Comments

  1. marcdelay
    Posted January 28, 2010 at 10:04 pm | Permalink

    “I now use other tools to track what requests are being sent back and forth instead between my application and facebook.”

    What are these other tools?
    Why bother making a post about something that is so useless you wont even use it yourself?

    • Posted January 31, 2010 at 7:38 pm | Permalink

      Well, yeah when I re-read it it can be missinterpreted: my point was: since this setting is usually by default on, you easily forget about it – so in a ajax environment do not use this setting.

      What I use instead is mostly firebug.

      cheers