zoukankan      html  css  js  c++  java
  • 一些跨域问题

    问题1:console面板出现Access to Font at 'http://static.anhouse.com/iconfont_c4f1eed.wolf' from origin 'http://static.anhouse.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xf.pinganfang.com' is therefore not allowed access.报错。

    原因:Access-Control-Allow-Origin是HTML5中定义的一种服务器端返回Response header,用来解决资源(比如字体)的跨域权限问题。

    解决方案:需要后端或运维在nginx上添加一个同域的配置,把static这个域添加到同域。
    在nginx.conf中配置

    http {
      ......
      add_header Access-Control-Allow-Origin *;
      add_header Access-Control-Allow-Headers X-Requested-With;
      add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
      ......
    }

    问题2:打开本地html文件时,console面板出现

    Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.报错。

    原因:做本地文件上传,浏览器为了安全性考虑,默认对跨域访问禁止。

    解决方案:给浏览器传入启动参数(allow-file-access-from-files),允许跨域访问。

    Windows下,运行"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" --allow-file-access-from-files

  • 相关阅读:
    仿函数(functor)
    七周七语言
    面向签名编程
    git checkout简介
    .gitkeep常用写法
    PhpStorm terminal无法输入命令的解决方法
    原 在windows上创建文件名以“.”开头的文件
    cmd 里面运行git提示“不是内部或外部命令,也不是可运行的程序”的解决办法
    .gitkeep
    git/github运用
  • 原文地址:https://www.cnblogs.com/camille666/p/cross_domain_cases.html
Copyright © 2011-2022 走看看