request.xhr? not detecting AJAX requests from facebook

4 views
Skip to first unread message

stupakov

unread,
Nov 23, 2009, 7:18:40 PM11/23/09
to facebooker
I have the same problem as what's described in the thread:
http://groups.google.com/group/facebooker/browse_thread/thread/4d5ca5b36659bc83
I'm starting a new thread because for some reason the "reply" option
is not available in that thread. (old thread?)

I've tried all the suggestions for detecting an ajax request in my
controller:
[code]
if request.parameters["fb_sig_is_mockajax"] == "1" ||
request.parameters["fb_sig_is_ajax"] == "1" || request.xhr? ||
request.xml_http_request?
render :partial => "comments_for_gift", :locals => { :gift =>
comment_gift }
else
redirect_to home_url
end
[/code]

And in call cases, the if statement evaluates to false and I get
redirected to home_url. I've also tried respond_to do |format|
format.fbjs { .... and this never gets called either.

My view code is:
[code]
<% remote_form_for Comment.new, :update => "comments_for_#
{gift.id}" do %>
<%= text_area_tag :body, "", :style => "width:400px"
%> <br/>
<%= hidden_field_tag :comment_gift, gift.id %>
<%= submit_tag "Post" %>
<% end %>
[/code]

The html code that gets generated is:
[code]
<form id="app319018635467_new_comment" class="new_comment"
fbcontext="660a00b127bf"
onsubmit="fbjs_sandbox.instances.a319018635467.bootstrap();return
fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,
319018635467),function(a319018635467_event) {new
a319018635467_Ajax.Updater('comments_for_149', '/dear_santa/comments',
{asynchronous:true, evalScripts:true,
parameters:a319018635467_Form.serialize($FBJS.ref(this))}); return
false;},319018635467],new fbjs_event(event));" method="post" action="/
dear_santa/comments">
<input type="hidden" value="en_US" name="fb_sig_locale"/>
.... etc... ( fb_sig fields)
<textarea id="app319018635467_body" fbcontext="660a00b127bf"
style="width: 400px;" name="body"/>
<br/>
<input id="app319018635467_comment_gift" type="hidden"
fbcontext="660a00b127bf" value="149" name="comment_gift"/>
<input type="submit" value="Post" name="commit"/>
</form>
[/code]

According to Firebug, I do get a javascript error when I submit the
form:
[code]
function (a319018635467_event) {
a319018635467_Form is not defined >>>>> new
(a319018635467_Ajax.Updater)("comments_for", "/dear_santa/comments",
{asynchronous: true, evalScripts: true, parameters:
a319018635467_Form.serialize($FBJS.ref(this))});
return false;
}
[/code]

I'm not too familiar with JS so I'm not sure what's going on there.

I have multiple forms on one page, but the same error occurs if I
only have one such form.
Any suggestions for what might be going on and what else I should
check would be appreciated.

Philip Hallstrom

unread,
Nov 23, 2009, 10:52:20 PM11/23/09
to faceb...@googlegroups.com
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can't do this. That line originally looked like:

paramters:Form.serialize(.....).....

Facebook rewrites all of that to prepend your app id which breaks
things.

Check this out for how to do fake ajax...

http://wiki.developers.facebook.com/index.php/Mock_AJAX

Good luck!

-philip
> --
>
> You received this message because you are subscribed to the Google
> Groups "facebooker" group.
> To post to this group, send email to faceb...@googlegroups.com.
> To unsubscribe from this group, send email to facebooker+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=
> .
>
>

Reply all
Reply to author
Forward
0 new messages