服务端需要做改造.
1. 添加header
见下面代码.
@Override public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException,ServletException { HttpServletRequest request= (HttpServletRequest)servletRequest; System.out.println("a visit from :"+request.getRemoteAddr()); HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; httpServletResponse.setHeader("Access-Control-Allow-Origin","*"); httpServletResponse.setHeader("Access-Control-Allow-Headers","X-Requested-With,Content-Type"); httpServletResponse.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); filterChain.doFilter(servletRequest,servletResponse); }