Display diagnostics in text format for xhr request

Backport of https://github.com/rails/rails/pull/14745 to 4.1-stable
More details: https://github.com/rails/rails/commit/a725a453b38057b46878afae39dc107ada2cf326#commitcomment-8835104
Thanks @jontebol for the report!