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

江枫思渺然 提交于 2020-01-10 08:24:18

问题


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.


回答1:


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)




回答2:


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"


来源:https://stackoverflow.com/questions/18137094/how-to-allow-access-control-allow-origin-aka-cross-domain-on-wampserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!