Permalink
Browse files

Added Request#xml_http_request? (and an alias xhr?) to that'll return…

… true when the request came from one of the Javascript helper methods (Ajax). This can be used to give one behavior for modern browsers supporting Ajax, another to old browsers #1127 [Sam Stephenson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1194 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7cda492 commit 95e6c03de7cd52a426560a6c46bd08b1791d7022 @dhh dhh committed Apr 17, 2005
Showing with 10 additions and 0 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +8 −0 actionpack/lib/action_controller/request.rb
@@ -1,5 +1,7 @@
*SVN*
+* Added Request#xml_http_request? (and an alias xhr?) to that'll return true when the request came from one of the Javascript helper methods (Ajax). This can be used to give one behavior for modern browsers supporting Ajax, another to old browsers #1127 [Sam Stephenson]
+
* Deprecated the majority of all the testing assertions and replaced them with a much smaller core and access to all the collections the old assertions relied on. That way the regular test/unit assertions can be used against these. Added documentation about how to use it all.
* Fixed DateHelper to return values on the option tags such that they'll work properly in IE with form_remote_tag #1024 [rscottmace@gmail.com]
@@ -122,6 +122,14 @@ def path_parameters
@path_parameters ||= {}
end
+ # 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?
+
#--
# Must be implemented in the concrete request
#++

0 comments on commit 95e6c03

Please sign in to comment.