跨域请求
介绍:跨域请求就是在项目中,前段页面发送的请求,访问其他模块的 资源,而引发的问题
实例:http.get('http://localhost:9107/cart/addGoodsToCartList.do?itemId='
+ $scope.sku.id +'&num='+$scope.num).success(
1、xml 配置
在被请求的资源中,Controller 设置
response.setHeader("Access-Control-Allow-Origin", "http://localhost:9105");
response.setHeader("Access-Control-Allow-Credentials", "true");
Access-Control-Allow-Origin 是 HTML5 中定义的一种解决资源跨域的策略。
他是通过服务器端返回带有 Access-Control-Allow-Origin 标识的 Response header,用来
解决资源的跨域权限问题。
在被请求的资源中进行配置【在请求路径后 添加 {'withCredentials':true}】
$scope.addToCart=function(){
$http.get('http://localhost:9107/cart/addGoodsToCartList.do?itemId='
+ $scope.sku.id +'&num='+$scope.num,{'withCredentials':true}).success\
2、使用注解进行配置
@CrossOrigin(origins=“http://localhost:9105”,allowCredentials=“true”)
allowCredentials=“true” 可以缺省
博客主要介绍了跨域请求,提及使用注解进行配置,给出了 @CrossOrigin 注解示例,其中 allowCredentials=\true\ 可缺省,origins 设为 \http://localhost:9105\。

224

被折叠的 条评论
为什么被折叠?



