From 95e6c03de7cd52a426560a6c46bd08b1791d7022 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 17 Apr 2005 16:40:53 +0000 Subject: 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 --- actionpack/lib/action_controller/request.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 6e73a69ed7..032b19d6eb 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -122,6 +122,14 @@ module ActionController @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 #++ -- cgit v1.2.3