I have read lot of things about CORS and how allowing Access-Control-Allow-Origin: * is security vulnerability to web server. But none of the article explained about how we can allow HTML5 hybrid application to access web services hosted on some domain which disallowed the wildcard char *
My question is: as far as my knowledge HTML5 hybrid app does not run on any specific domain that can we set as a whitelisted domain at the Access-Control-Allow-Origin lists. Then how we can still access the web service data from the hybrid APP request data through ajax call over web server which disallowing * under Access-Control-Allow-Origin tag?
I have build a lot of hybrid apps using phonegap, jquery and ajax. You can set your CORS in php files or in .htaccess files as follow and it will work.
For .htaccess file use this
Alternatively, you can integrate the code below at very first top of all .php files to be access via cross domain. Just know that symbol * makes all domain accessible as well