request.xhr? not detecting AJAX requests from Facebook

4 views
Skip to first unread message

Darren Torpey

unread,
Apr 24, 2009, 12:33:49 AM4/24/09
to facebooker
Here's the *other* problem I ran into...

To recap:

Within the last two weeks, I installed Facebooker using the normal
(script/plugin install git://github.com/mmangino/facebooker.git)
route.

I just got through Chapter 7 of Mangino's Facebooker book, but the
AJAX comment system wasn't working. Once I fixed the paramaters-
parsing error, I found that request.xhr? was not returning true when
the AJAX call was received.

I noticed that Facebook was in fact sending the fb_sig_is_ajax => 1
parameter, so I figured there was something wrong with how Facebook
and xhr? were interacting.

I found the facebook_request_fix.rb file, which seemed to be
addressing this very issue by checking for the "fb_sig_is_mockajax"
and "fb_sig_is_ajax" parameters as indicators that FB was sending us
an AJAX request. However, I also found that that fix is not
implemented for Rails 2.3 and higher, and I am running Rails 2.3.2.

Is Rails 2.3 somehow supposed to understand some indicator from
Facebook that the request is AJAX? Or is there some other code that is
supposed to be dealing with this?

For now, I'm simply checking for

request.parameters["fb_sig_is_mockajax"] == "1" ||
request.parameters["fb_sig_is_ajax"] == "1" || request.xhr?

to see if the request is AJAX, so I'm okay.

But I figured there must be something wrong here, so I wanted to bring
it up on the list.

Ivor Paul

unread,
Apr 24, 2009, 3:21:49 AM4/24/09
to faceb...@googlegroups.com
I am experiencing the same issue with remote_form_for as shown on page 137 in mikes book.

Regards
Ivor

Mike Mangino

unread,
Apr 24, 2009, 8:23:46 AM4/24/09
to faceb...@googlegroups.com
It sounds like that got missed in the move to 2.3. I'd love patches from one of you to fix that!

Mike

Ivor Paul

unread,
Apr 28, 2009, 3:09:14 AM4/28/09
to faceb...@googlegroups.com
I played  around with this but could not solve yet.
I did find that the controller method :xml_http_request? works - as in

if xml_http_request?
  #this is ajax
else
  #this is not ajax
end

What I have done for the time being is use the repond_to blocks like so:

respond_to do |format|
  format.fbjs {
    #this is ajax
  }
  format.fbml {
    #this is not ajax
  }
end

If there is an issue with this approach that I am not considering please let me know.

When I have a moment I will go back and see if I can figure out what is up with the request.xhr?

Regards
Ivor

Darren Torpey

unread,
May 14, 2009, 11:30:49 PM5/14/09
to faceb...@googlegroups.com
It turns out that if you just put:

xml_http_request?

instead of

request.xhr?

it works as expected with Facebook, because of what's defined in 

lib/facebooker/rails/controller.rb

For my money, I'm all set with using xml_http_request? but I'm not sure what the "best practice" is considered to be on that these days.

~Darren
Reply all
Reply to author
Forward
0 new messages