AJAX跨域问题
可以不可以后端不做跨域的任何处理,全部让前端来做,比如Nginx?
可以不可以后端不做跨域的任何处理,全部让前端来做,比如Nginx?
2018-12-08
可以前端做,但是一般都是后端做,写一个统一过滤器也可以
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
chain.doFilter(req, res);
}
举报