request.xhr? is only for Prototype? 3

Posted by Justin Reagor Wed, 26 Mar 2008 17:12:00 GMT

I just found this lovely tid-bit of information in the ActionController::AbstractRequest class…

# Returns true if the request's "X-Requested-With" header contains
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
def xml_http_request?
    !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i)
end
alias xhr? :xml_http_request?

Mental note for later: Make sure to set this header when using jQuery in future projects…. Not sure if jQuery does this already (probably not).

Comments

Leave a response

  1. Avatar
    JHill about 1 hour later:
    jQuery sets it, too.
  2. Avatar
    Randy about 3 hours later:
    I was going to say that I follow this: http://ozmm.org/posts/jquery_and_respond_to.html But it looks like Jason already answered you question :-)
  3. Avatar
    eric 1 day later:
    HA HA! Now you're wrong three times!
Comments