You can check it like this:
$isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
If you are only waiting for access via XHR, then simply exitif this header is not there.
Note . This title is trivial to replace. Don't rely on it for anything, but it looks like it came from na XHR.