views:

559

answers:

1

hi!

i'm building a RoR app for facebook using FBML and the Prototype JavaScript library.

what i'm trying to do is have a div automatically refreshed, using the neat periodically_call_remote, which creates a PeriodicalExecuter object.

here's the code:

 <%= render :partial => "status_item", :collection => @status %>
 <%= periodically_call_remote( :url => { :action => :status, :id => @hunt.id }, :update => 'status_div') %>

i'm getting 2 kinds of errors:

  1. SyntaxError: Parse error's on fbml_static_get.php on http://biascica.pipps.net:8888/javascripts/prototype.js?1246455754 and the likes (effects.js and controls.js)

  2. ReferenceError's: can't find variable a116508001384_PeriodicalExecuter

this is the javascript code, as modified by facebook:

new a116508001384_PeriodicalExecuter(function() {new a116508001384_Ajax.Updater('status_div', '/corinna_test/servers/ren%C3%A9/treasure_hunts/12/status', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + a116508001384_encodeURIComponent('qBY5jTvJ04rEcvLsQzkhNkEhRXN1wRA2ITrgq/4JmVg=')})}, 10)

(notice how they appended a116508001384_ in front of almost everything)

i'm also getting iframex errors but i don't think that's a priority right now.

can anyone help me make sense of this mess?

thanks! asymmetric

+1  A: 

You can't do this. Facebook has its own restricted version of Javascript called Facebook Javascript (FBJS). You need to use Facebook's Ajax object. The prototype API stuff won't work with FBJS. You need to use FBJS or put your application in an iframe.


function doAjaxStuff() {
    var ajax = new Ajax();
    var params = { param1: 'param1' };
    ajax.responseType = Ajax.FBML;
    ajax.ondone = function(data) { $('div').setInnerFBML(data); };
    ajax.onerror = function() { $('div').setTextValue('error...'); };
    ajax.post(URL, params); 
}

Pierre-Antoine LaFayette