静态资源跨域解决办法--nginx

1,144 阅读1分钟

api 已做跨域处理,感兴趣的可以看 barryvdh/laravel-cors 下面是对 public/img 下的图片做的跨域处理

nginx 配置

      location ~ /img {

          add_header Content-Type 'text/html; charset=utf-8';
          add_header Access-Control-Allow-Origin *; 
          return 200 '{"msg":"/api/"}'; 测试时确保命中
      }

ajax 请求

            $.ajax({
        type:'GET',                
url:"http://localhost/img/1.png",