Angularjs 以ajax格式发送Cookie
我想在http调用中发送文档cookie。 我已使用withCredentials,但它只能发送浏览器级别的cookie。 我也使用跨域,但它工作不好。 下面是我正在使用的代码Angularjs 以ajax格式发送Cookie,angularjs,Angularjs,我想在http调用中发送文档cookie。 我已使用withCredentials,但它只能发送浏览器级别的cookie。 我也使用跨域,但它工作不好。 下面是我正在使用的代码 $http({ method: 'GET', url: url, xhrFields: { withCredentials: true }, crossDomain: true, header:{ 'SHOPSESSIONID' : sessionStorage.getIt
$http({
method: 'GET',
url: url,
xhrFields: { withCredentials: true },
crossDomain: true,
header:{ 'SHOPSESSIONID' : sessionStorage.getItem("SHOPSESSIONID") }
}).success(function(data){
return data;
}).error(function(data){
return data;
});
在配置阶段使用
$httpProvider
:
app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.withCredentials = true;
}])
您可以放弃xhrFields
和crossDomain
比例
顺便说一句,angular使用
然后
代替成功
,并使用捕获
代替错误
。(这是语法)您面临的错误是什么?添加行后,它显示“当凭据标志为true时,不能在“Access Control Allow Origin”标题中使用通配符“*”,现在使用以下代码。(function(){'use strict';angular.module('app').config(['$httpProvider',function($httpProvider){$httpProvider.defaults.withCredentials=true;$httpProvider.defaults.crossDomain=true;}])service('UtilityService',['$log','$q','$http',function($log,$q,$http){this.getHTTPGET=function(url){返回$http({method'GET',url:url})。然后(函数(数据){return data;}).catch(函数(数据){return data;});};};}]);}();您需要更改服务器端视图中的Access Control Allow Origin
头