The problem you're facing is related to the fact that it is in fact an internal request. Because of that the headers you're sending are not populating $_SERVER
environment info array. They're kept inside $this->request->headers()
instead.
The ajax check is done in based on $_SERVER contents, like this:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']))
{
// Typically used to denote AJAX requests
$requested_with = $_SERVER['HTTP_X_REQUESTED_WITH'];
}
The only solution that would not include is_internal()
check would be to make this request an external one and to do that you'd have to set the request URL to include protocol (http://
) and full domain name - essentially a full address. Then, the request will populate $_SERVER array with new headers and is_ajax()
should let it through.