打赏

前端跨域解决方案汇总

跨域解决方法汇总

(1)JSONP

(2)CORS(后端实现)

(3)webSocket

(4)node代理(先发给同域node服务器,同域服务器再发给真正服务器)

(5)Nginx代理

conf/nginx.conf配置:

 # 新加的
        location /spring {
            proxy_pass   http://120.79.197.130:8530; # 后端接口 IP:port
        }

请求代码:

$.ajax({
    type: "get",
    url: "/spring/user/get", // 注意链接
    success: function(result) {
        console.log(result);
    }
});    

页面代码上传到nginx服务器相应路径。

访问nginx服务器上的页面,解决跨域问题。

 

posted @ 2020-04-05 20:45  孟繁贵  阅读(319)  评论(0编辑  收藏  举报
TOP