[Facebooker-talk] Showing updated facebook_messages after Ajax failure
Alan Larkin
alan.larkin at gmail.com
Sat Jan 10 08:10:20 EST 2009
I'm trying to work out how to update facebook_messages when an Ajax request fails.
I thought I would do something based on the Ajax/JSON example in Mangino's book.
So I created a created a partial which simply renders facebook_messages:
# views/shared/_messages.fbml.erb
<div id="messages">
<%= facebook_messages %>
</div>
In my controller's error handling section I do something like:
respond_to do |format|
format.json do
flash[:error] = 'An error message'
render :json => { :ids => [:messages],
:fbml_messages => render_to_string(:partial =>
'shared/messages.fbml.erb')
}, :status => 500
end
end
And in my view use:
"function(data) {
for(var i = 0; i < data["ids"].length; i++) {
var id = data["ids"][i];
$(id).setInnerFBML(data["fbml_" + id]);
}
}"
as the failure callback.
However, unlike the success callback, the failure callback does not receive any
arguments, so the message partial which was rendered to string is unavailable
and thus cannot be used to update the page!
If instead I try to use fb:js-string to convert the FBML for displaying the
facebook_messages to a Javascript variable, it will only be evaluated once, when
the page loads, and thus not show any subsequent updates of the flash variables
due to Ajax requests.
So what the hell does one do??
--
<a href="http://wikimediafoundation.org/wiki/Donate/en"><img border="0"
alt="Wikipedia Affiliate Button"
src="http://upload.wikimedia.org/wikipedia/foundation/5/58/2008_fundraiser_micro_button-en.png"
/></a>
More information about the Facebooker-talk
mailing list