On one of my sites, I was using services to export data to a flash widget that could be embedded on any website. However, flash doesn't play very nicely with Facebook apps, so I looked at doing a little cross-domain scripting using the JSON_Server. However, in looking at the code for the JSON server, I noticed that it only supports POSTs. I added a litte GET functionality to json_server.module (see attached patch), and then I was able to do this:
function get(){
headElement = document.getElementsByTagName("head").item(0);
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
// The callback parameter is needed so that the JSON gets returned correctly in order to be handled by the output function
script.setAttribute("src","http://server.com/services/json?method=views.getView&view_name=some_view&callback=display");
headElement.appendChild(script);
}
function display(obj){
var theDiv = document.createElement("div");
theDiv.innerHTML = obj.data;
document.body.appendChild(theDiv);
}
Then in my facebook app (or any other site I wish to display my widget on), I can simply include the source of my javascript and call the get() function:
<script src="http://server.com/path/to/javascript.js"></script>
<script type="text/javascript">get();</script>
| Comment | File | Size | Author |
|---|---|---|---|
| json_server.20080403.patch | 1000 bytes | ebeyrent |
Comments
Comment #1
andremolnar commentedMarking this one as a dupe as there is now a newer ongoing discussion and patch at http://drupal.org/node/317035