getリクエストからどのように応答ヘッダーにアクセスできますか?.then関数の応答ヘッダーにアクセスするにはどうすればいいですかAngularJS
私は約束を返すサービス機能を持っています。私のコントローラは、私が応答ヘッダーからコンテンツの種類が必要です機能を約束を解決します。
私はconsole.log(ヘッダー())で表示される "ヘッダー"パラメーターを使用しようとしましたが、エラー "ヘッダー()はコンソールに表示されていません"。
マイサービス:
.factory('GetResultFile',
['$http', '$q',
function ($http, $q) {
var service = {};
service.getResult = function(id, rid) {
var deferred = $q.defer();
$http
.get('http://localhost:9999/v1/jmeter/' + id + '/results/' + rid, {cache: false})
.then(function(data, status, headers, config) {
if(data.status == 200) {
console.log(data.status);
deferred.resolve(data);
}
else {
deferred.reject(data);
}
});
return deferred.promise;
}
return service;
}])。
コントローラ:
$scope.getResult = function(rid) {
console.log($scope.id);
GetResultFile.getResult($scope.id, rid)
.then(function(data, headers) {
//console.log(headers.Content-type);
console.log(headers());
console.log(data);
console.log("Download succeed");
console.log(data.status);
var file = new Blob([data.data], {type: 'text/plain;charset=utf-8'});
FileSaver.saveAs(file, 'test.txt');
}, function (data) {
console.log("Download ERROR!");
console.log(data.status);
})
};
}])
あなたはあなたのサービスのコードを追加してくださいでした。 –
[anglejsでレスポンスヘッダーを読む方法]の複製がありますか?(http://stackoverflow.com/questions/28805589/how-to-read-response-headers-in-angularjs) –
私の回答を更新しました。 @MoshFeuああ、私は私の答えをチェックし、それはあなたを – Kai