您的位置:首页 > 理论基础 > 计算机网络

XMLHttpRequest cannot load http://XXXx.json. No 'Access-Control-Allow-Origin' header is present on t

2016-06-17 21:22 801 查看
XMLHttpRequest cannot load http://0.0.0.0:3000/6a5bec410cd2f01435bc.hot-update.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4130' is therefore not allowed access.


今天遇到这个问题   浏览器通过服务器A 服务区获得文件服务器的一个json 文件 结果报错 这个错误

 有两个解决办法 1

1  是使用jsonp 去请求服务 , 

2 在控制器回传给浏览器的值 response ,addheader值 

 增加  

headers: { "Access-Control-Allow-Origin": "*" }


不过我这个比较特殊 是像文件服务器直接请求json文件

 _global_viewer.loadModel('http://prodfs1.XXXX.com.cn/rst_basic_project/manifest.json');

这个文件又是通过nginx 代理找到 在文件服务器的位置

想了半天。。查了半天  没有解决思路

最后想到直接给nginx 添加header 模拟http 

nginx配置文件如下

server {
listen 80 default_server;
add_header Access-Control-Allow-Origin '*' ;
listen [::]:80 default_server;

root /root/mnt/bimatrix_fs;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name localhost;增加了 

add_header  Access-Control-Allow-Origin '*' ; 

问题解决。。浪费了半天时间  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: