In my custom component, I have a controller to receive requests from external sites, desktop and mobile applications, the returned data in JSON format.
I encounter CORS (Cross-origin resource sharing) issue if the request is made from web application (using AngularJS), so I want to set Access-Control-Allow-Origin header to enable CORS.
However, setting header("Access-Control-Allow-Origin: *") only solves the problem if it is put in the index.php in Joomla's root folder. It doesn't take effect if it is in the controller (mycontroller.json.php). I only want Access-Control-Allow-Origin takes effect in my controller only, not the whole website.
Asking my end-users to edit their's index.php or edit .htaccess file is not a good solution at all, they are not technical users and when they update Joomla their customizations are gone.
If you have any idea to solve this CORS issue or there is any way to handle this kind of task, please let me know. I really appreciate. Thanks!