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).