How to read response headers in angularjs?

前端 未结 7 1368
终归单人心
终归单人心 2020-11-27 17:17

My server returns this kind of header: Content-Range:0-10/0:

\"enter

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 17:27

    Use the headers variable in success and error callbacks

    From documentation.

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

    If you are on the same domain, you should be able to retrieve the response headers back. If cross-domain, you will need to add Access-Control-Expose-Headers header on the server.

    Access-Control-Expose-Headers: content-type, cache, ...
    

提交回复
热议问题