朱争光

一点点攒起我的那片天

  • 主页
  • 文章分类
  • 标签
  • 我

朱争光

一点点攒起我的那片天

  • 主页
  • 文章分类
  • 标签
  • 我

ajax跨域

2015-03-13

跨域的解决方式是CORS CORS介绍
弄了好久,其实只要允许options请求,在head内加入标识允许字段即可。
但是老项目的原因,权限动不了,options会302跳登录界面
就想到用nginx前端过滤
1.正常情况下,跳转到服务器
2.遇到options请求,直接返回,并带上指定head

1
2
3
4
5
6
7
8
9
10
11
12
13
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, DELETE";
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Access-Control-Max-Age 3600;
add_header Content-Type text/plain;
return 200;
}
proxy_pass http://zzg-dev.zgfh.xyz;
}

问题:目前ajax跨区不允许302等跳转,感觉没必要,就没再查解决方法

eclipse 环境配置
ubuntu 安装 pip
豫ICP备17013970号-1 | Copyright © daozzg.com 保留所有权利。2019 朱争光