如何在 wampserver 上允许 ACCESS-CONTROL-ALLOW-ORIGIN 也就是跨域 [英] how to allow ACCESS-CONTROL-ALLOW-ORIGIN aka cross-domain on wampserver

查看:33
本文介绍了如何在 wampserver 上允许 ACCESS-CONTROL-ALLOW-ORIGIN 也就是跨域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XMLHttpRequest 无法加载 https://webservice.com?param=hahah.Access-Control-Allow-Origin 不允许来源 http://{domain}.

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

当我尝试通过 wampserver 进行 web 服务调用时,我得到了这个,我如何在 wampserver 上启用它?

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

或者我怎么可能只用 jsonP 来获取 xml 数据而 javascript 不会抛出错误.

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

推荐答案

你必须先启用 headers 模块,像这样:

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

  • 点击系统托盘中的 wamp 图标
  • 转到 Apache > Apache 模块
  • 选中headers_module"选项

然后将其包含在您的 apache 配置中:

And then include this in your apache config:

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

(在 httpd.conf 或您的 vhost 配置中)

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

(除了*你也可以指定一个特定的域)

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

这篇关于如何在 wampserver 上允许 ACCESS-CONTROL-ALLOW-ORIGIN 也就是跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆