Cross-Origin Resource Sharing (CORS) (Ajax Cross Domain issue)

PHP:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, x-api-key');
header('Test-Header: Rex');

.htaccess

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type, x-api-key"
Header add Access-Control-Allow-Methods "GET,POST,OPTIONS,DELETE,PUT"
Header add Test-Header "Rex"

Enable header module on Apache:

a2enmod headers

IIS:

Image 4

Reference:

  1. http://blog.toright.com/posts/3205/%E5%AF%A6%E4%BD%9C-cross-origin-resource-sharing-cros-%E8%A7%A3%E6%B1%BA-ajax-%E7%99%BC%E9%80%81%E8%B7%A8%E7%B6%B2%E5%9F%9F%E5%AD%98%E5%8F%96-request.html
  2. http://stackoverflow.com/questions/10640596/header-set-access-control-allow-origin-in-htaccess-doesnt-work
  3. http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2