AngularJS $resource 不发送 X-Requested-With [英] AngularJS $resource not sending X-Requested-With
本文介绍了AngularJS $resource 不发送 X-Requested-With的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 angular 1.1.5 并且我正在使用 $resource 为 REST 服务制作 XHR,但似乎 $resource 没有将标头作为 X-Requested-With 附加为 XMLHttpRequest,这是正常行为吗?我是否需要手动附加标题?
I'm using angular 1.1.5 and I'm using a $resource to make a XHR to a REST service but it seems like the the $resource isn't appending the header as X-Requested-With as XMLHttpRequest, is that a normal behavior? and Do I need to append the header manually?
function loginCtrl($scope,$resource) {
$scope.submit = function () {
var resource = $resource('/Api/User/login', {},
{
authenticate: {
method: 'POST',
isArray: false,
headers: {
'__RequestVerificationToken': $scope.loginRequest.Token
}
}
});
resource.authenticate($scope.loginRequest);
};
}
推荐答案
只需将此添加到您的应用程序
Just add this to your app
myAppModule.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
}]);
这篇关于AngularJS $resource 不发送 X-Requested-With的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文