【问题标题】:Request Header in Success请求标头成功
【发布时间】:2014-11-10 18:25:46
【问题描述】:

在 Angular 服务中,我使用 $http.get('some/url/') 发出获取请求。我需要检查文件名的内容配置是否成功。我不确定是否有办法访问标题,所以现在我正在使用。有没有办法在success函数中获取headers?

【问题讨论】:

    标签: javascript angularjs promise


    【解决方案1】:

    有没有办法在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.
      });
    

    【讨论】:

    • 正要在评论中准确地说出来。 OP 在询问之前显然懒得看文档。
    【解决方案2】:

    你可以的

    $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);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2017-10-07
      相关资源
      最近更新 更多