Skip to content

Instantly share code, notes, and snippets.

@swinton
Created May 26, 2010 12:38
Show Gist options
  • Save swinton/414418 to your computer and use it in GitHub Desktop.
Save swinton/414418 to your computer and use it in GitHub Desktop.
<h1>Hello, here is an example of using JSONP within a Facebook page</h1>
<p>This is based on the example from the <a href="http://wiki.developers.facebook.com/index.php/FBJS/Examples/Ajax">Ajax examples</a> in the wiki.</p>
<div id="spotlight">
result should load here...
</div>
<script>
// 1. Instantiate our Ajax instance
var ajax = new Ajax();
var spotlightDiv = document.getElementById("spotlight");
spotlightDiv.setInnerFBML("testing...");
ajax.responseType = Ajax.JSON;
// 2. Set up handlers
ajax.ondone = function(data) {
spotlightDiv.setInnerFBML("yay!");
};
ajax.onerror= function(data) {
spotlightDiv.setInnerFBML("yah boo sucks to you!");
};
// 3. Make the request
ajax.post('http://c4.labs.nixmc.com/spotlight.json');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment