Access to XMLHttpRequest at “ xxx” from origin 'null' has been blocked by CORS policy解决方法

本人搭建好PHP后端框架并部署到服务器上后,前端访问后端接口发生了 Access to XMLHttpRequest at “ xxx” from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.的错误,查找了网上若干方法,用下面这种方法解决问题:

 

修改服务器上的Apache配置文件/etc/httpd/conf/httpd.conf或/etc/apache2/apache.conf(不同linux服务器的apache配置文件位置)

Access to XMLHttpRequest at “ xxx” from origin 'null' has been blocked by CORS policy解决方法_第1张图片


    AllowOverride All
    # Allow open access:
    Require all granted
   

中间加上Header set Access-Control-Allow-Origin *    #允许所有域名跨域访问

保存退出

 

 

 

建议将前后端源码部署到服务器上访问,保证安全性。

你可能感兴趣的:(服务器)