ajax跨域问题在后台解决是,只需要在过滤器中添加如下配置即可:
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With,Content-Type,Accept,Authorization,token,key,mark");
response.setHeader("Access-Control-Expose-Headers", "token,Content-Disposition");
碰到的问题:在前端发送Get请求时,没有跨域问题,请求正常;但是当发送post请求,且请求的body中有数据时,就一直报跨域问题:
找了半天,也没解决,最后仔细查看代码,终于发现问题:
问题代码:
修改后的代码:
看出区别了吗?没错,就是头:Content-Type中间的短线是短划线,不是下划线
特此记录