异步跨域请求

解决异步跨域请求

跨域:域名,端口,协议不同都为跨域

  1. 设置请求头在被跨域的服务器代码上,
response.setHeader("Access-Control-Allow-Origin", "http://localhost:8080");
response.setHeader("Access-Control-Allow-Credentials", "true");
  1. 如果使用的是springMVC框架可以使用注解
//放在方法上表示此方法允许(http://www.xxxx.com)网站,异步请求此方法
@CrossOrigin(origins= {"http://www.xxxx.com"}) 
  1. 如果需要在跨域的同时共享cookie时可以使用
//放在异步请求的路径上
{'withCredentials':true}
//比如
$http.get('http://localhost:9107/cart/addGoodsToCartList,{'withCredentials':true})

猜你喜欢

转载自blog.csdn.net/qq_43338182/article/details/82965868