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.
Simply add a header to your HttpServletResponse by calling addHeader : response. addHeader("Access-Control-Allow-Origin", "*");
To initiate a cross-origin request, a browser sends the request with an Origin: <domain> HTTP header, where <domain> is the domain that served the page. In response, the server sends Access-Control-Allow-Origin: <domain> , where <domain> is either a list of specific domains or a wildcard to allow all domains.
You can bypass cross-domain request issues by using the Authorization Code Flow instead and making your calls directly from the server, which securely stores your client secret.
CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.
You have to enable the headers module first, like so :
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)
Hope this will solve your problem -
To add the CORS authorization to the header using Apache, simply add the following line inside either the , , or sections of your server config (usually located in a *.conf file, such as httpd.conf or apache.conf), or within a .htaccess file:
For all requests -
Header set Access-Control-Allow-Origin "*"
For trusted hosts -
Header set Access-Control-Allow-Origin "your-ip/domain-here"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With