How to distinguish ajax from not ajax requests in Piwik code

one of free hostings is very dumb and injects advertisements in every text/html response and breaks piwik’s output,
but if the response has Content-Type: text/plain everything is ok.
The question is: how to distinguish Ajax from not Ajax on the server side or in Piwik’s code, so I can use
Content-Type: text/plain for XHR requests?
No, I can’t change the hosting.