【发布时间】:2014-11-10 18:25:46
【问题描述】:
在 Angular 服务中,我使用 $http.get('some/url/') 发出获取请求。我需要检查文件名的内容配置是否成功。我不确定是否有办法访问标题,所以现在我正在使用。有没有办法在success函数中获取headers?
【问题讨论】:
标签: javascript angularjs promise
在 Angular 服务中,我使用 $http.get('some/url/') 发出获取请求。我需要检查文件名的内容配置是否成功。我不确定是否有办法访问标题,所以现在我正在使用。有没有办法在success函数中获取headers?
【问题讨论】:
标签: javascript angularjs promise
有没有办法在success函数中获取headers?
如AngularJs $http Documentation, second paragraph中所见逐字逐句
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
【讨论】:
你可以的
$http.get('/some/Url').then(function(successResponse){
console.log(successResponse); // this will print out the response object and you can access headers, config, data, etc.
}, function(failureResponse){
console.log(successResponse);
});
【讨论】: