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

  • 相关阅读:
    Python连接MySQL数据库之pymysql模块使用
    前端基础之BOM和DOM
    前端基础之JavaScript
    前端基础之CSS
    前端知识之HTML内容
    Python基础—名称空间(Day10)
    Python基础—装饰器(Day11)
    Python基础—迭代器、生成器(Day13)
    Python基础—文件操作(Day8)
    Python基础—函数(Day9)
  • 原文地址:https://www.cnblogs.com/camille666/p/cross_domain_cases.html
Copyright © 2011-2022 走看看