You can't call a PHP file outside the scope of Joomla when that PHP file uses Joomla or CB API. When you're doing that you're just loading a PHP file. It has no idea Joomla even exists when you do that. You need a Joomla component ajax endpoint or a CB component plugin for an ajax endpoint. Without either of those you can't access anything in Joomla or CB unless you manually load the entire Joomla structure from your own script to prepare Joomla.
Please see the below Joomla tutorial regarding ajax usage.
docs.joomla.org/Using_Joomla_Ajax_Interface
Ajax response information can also be found in the below tutorial.
docs.joomla.org/JSON_Responses_with_JResponseJson
If you just need to render the username in a Joomla article for example you can use CB Content Bot and the [username] substitution after setting the bot to use the viewing user instead of the author. This may work on modules if the module processes content plugins, but I have not tested that; however for that case we also have CB Content Module which works like a Custom HTML module except it supports substitutions.