rails/rails — pull request #14425 by ybart (2014-03-19 13:28:38+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.