how to allow ACCESS-CONTROL-ALLOW-ORIGIN aka cross-domain on wampserver

user2167582 picture user2167582 · Aug 9, 2013 · Viewed 43.3k times · Source

XMLHttpRequest cannot load https://webservice.com?param=hahah. Origin http://{domain} is not allowed by Access-Control-Allow-Origin.

I get this when I try to make a webservice call through wampserver, how could I enable this on wampserver?

or how may i just jsonP to obtain xml data without javascript throwing an error.

Answer

marty picture marty · Jan 9, 2014

You have to enable the headers module first, like so :

  • click on the wamp icon in your systray
  • go to Apache > Apache modules
  • check the option 'headers_module'

And then include this in your apache config:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin: *
</IfModule>

(in httpd.conf or in the configuration of your vhost)

(Instead of the * you can also specify a specific domain)