rails/rails — pull request #11397 by ybart (2013-07-10 15:43:52+00:00)
Title: Make CORS requests considered as Ajax requests

jQuery does not send the usual HTTP_X_REQUESTED_BY header that is
used by Rails to detect Ajax Request when using CORS. To overcome
this, a new cors? method was added to request, and this is used in
xhr? to determine wether the request is Ajax.

This fixes a problem where HTML page was returned instead of JSON
response because the CORS request was not considered as Ajax.

DIscussion: https://groups.google.com/forum/#!topic/rubyonrails-core/95jN3XLKJa4