跨域:浏览器同源策略 1995年,同源政策由 Netscape 公司引入浏览器。目前,所有浏览器都实行这个政策。 最初,它的含义是指,A网页设置的 Cookie,B网页不能打开,除非这两个网页"同源"。所谓"同源"指的是"三个相同"
协议相同 http https
域名相同 www.xdclass.net
端口相同 80 81
一句话:浏览器从一个域名的网页去请求另一个域名的资源时,域名、端口、协议任一不同,都是跨域
浏览器控制台跨域提示:
No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.
解决方法
JSONP
Http响应头配置允许跨域
nginx层配置
程序代码中处理通过拦截器配置
Nginx开启跨域配置
location下配置
location / {
add_header ‘Access-Control-Allow-Origin’ KaTeX parse error: Double superscript at position 64: …w-Credentials' '̲true';
add_…request_method = ‘OPTIONS’) {
add_header ‘Access-Control-Max-Age’ 1728000;
add_header ‘Content-Type’ ‘text/plain; charset=utf-8’;
add_header ‘Content-Length’ 0;
return 200;
}
}