has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ 前后端设置跨域问题解决过程

经过多次遇到坑,找了很多资料,有nginx配置,前端页面添加,等但是这些都没有解决遇到问题,下面是本人遇到的情况并解决步骤过程,希望看到对你有所帮助:

开发页面渲染生成海报,并保存   问题原因:

解决过程:
1:通过查询诸多资料:nginx代理配置域名新增(这个是大部分建议的结果):

   location ^~ /third_image/ {
              add_header 'Access-Control-Allow-Origin' "$http_origin" always;
              add_header 'Access-Control-Allow-Credentials' 'true' always;
              add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
              add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-  Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
              proxy_pass  图片路径地址;  //例如:https://image.XXX.com/
       }

配置了之后,前端读取还是一样的效果不可以,提示跨域问题,没有效果,没有解决,

2种设置情况在前端页面直接加 crossOrigin="anonymous"

以上这种情况也还是不能解决图片跨域的问题出现,

 

3:第三种情况是直接在js,中 img.setAttribute('crossOrigin', 'anonymous') 设置之后终于可以实现解决方案,

下面是设置的截图:

前端html页面设置:

最后实现了解决效果展示:

 

 

 

 

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
此插件为插件,打开后可访问接口,旧版浏览器可直接拖到扩展程序中安装,新版浏览器需要将扩展名修改成rar并解压,然后点击“加载已解压的扩展程序”安装。 ======================插件概述谷歌译文====================== 轻松将(Access-Control-Allow-Origin:*)规则添加到响应标头。 允许CORS:通过Access-Control-Allow-Origin,您可以轻松地在Web应用程序中执行Ajax请求。 只需激活插件并执行请求。默认情况下(在JavaScript API中),CORS源资源共享在现代浏览器中被阻止。安装此加载项将使您可以解除阻止此功能。请注意,将插件添加到浏览器后,默认情况下它处于非活动状态(工具栏图标为灰色C字母)。如果要激活加载项,请按一次工具栏图标。图标将变为橙色的C字母。 ======================插件概述谷歌译文====================== ========================插件概述原文======================== Easily add (Access-Control-Allow-Origin: *) rule to the response header. Allow CORS: Access-Control-Allow-Origin lets you easily perform cross-domain Ajax requests in web applications. Simply activate the add-on and perform the request. CORS or Cross Origin Resource Sharing is blocked in modern browsers by default (in JavaScript APIs). Installing this add-on will allow you to unblock this feature. Please note that, when the add-on is added to your browser, it is in-active by default (toolbar icon is grey C letter). If you want to activate the add-on, please press on the toolbar icon once. The icon will turn to orange C letter. ========================插件概述原文========================

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值